⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newsoper.java

📁 实现新闻系统的模糊查询功能
💻 JAVA
字号:
/*
 * 创建日期 2007-5-14
 *
 * TODO 要更改此生成的文件的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
package oper;

import java.util.ArrayList;
import java.sql.*;

import voo.New;
import db.DbConn;

public class NewsOper {

	public ArrayList Select(String title) {
		Connection con = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		ArrayList ar = new ArrayList();
		try {
			con = DbConn.getConn();
			pst = con
					.prepareStatement("select * from news where title like '%?%'");
			pst.setString(1, title);
			rs = pst.executeQuery();
			while (rs.next()) {
				New n = new New();
				n.setTitle(rs.getString(2));
				n.setDate(rs.getString(3));
				ar.add(n);
			}

		} catch (Exception e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		} finally {
			if (rs != null)
				try {
					rs.close();
				} catch (SQLException e) {
					// TODO 自动生成 catch 块
					e.printStackTrace();
				}
			if (pst != null)
				try {
					pst.close();
				} catch (SQLException e) {
					// TODO 自动生成 catch 块
					e.printStackTrace();
				}
			if (con != null)
				try {
					con.close();
				} catch (SQLException e) {
					// TODO 自动生成 catch 块
					e.printStackTrace();
				}
		}
		return ar;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -