public class JDBCUtil {
static Connection conn;
static PreparedStatement pstmt;
static ResultSet rs;
/*
* 查询
* 参数:查询SQL语句、参数的值
* 返回:查询结果集ResultSet
*/
public static ResultSet executeQuery(String sql,Object... params) throws SQLException{
conn=JdbcHelper.getConn();
pstmt=conn.prepareStatement(sql);
//设置参数
if(params!=null && params.length>0){
for(int i=1;i<=params.length;i++){
pstmt.setObject(i, params[i-1]);
}
}
//执行
rs=pstmt.executeQuery();
//关闭数据库
JdbcHelper.closeAll(conn, pstmt, rs);//??
return rs;
}