public ResultSet executeQuery(String sql){
ResultSet result=null;
ResultSet rs=null;
PreparedStatement pst=null;
try {
pst=con.prepareStatement(sql);
if(sqlValues!=null&&sqlValues.size()>0){ //当sql语句中存在占位符时
setSqlValues(pst,sqlValues);
}
rs=pst.executeQuery(sql);
result=(ResultSet) ResultSupport.toResult(rs); //一定要在关闭数据库之前完成转换
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
this.closeAll(con, pst, rs);
}
return result;
}
这是我调用的
public static int getworkeramount(){
DBHelper dh=new DBHelper();
int x=0;
String sql=new String("select count(perno) from per");
ResultSet rs=dh.executeQuery(sql);
try{
rs.next();
x=rs.getInt(1);
}
catch(Exception ex){
}
return x;
}
出现了这样的错误
com.microsoft.sqlserver.jdbc.SQLServerException: 对于 PreparedStatement 或 CallableStatement,方法 executeQuery() 不能带有参数。
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:1578)
at base.DBHelper.executeQuery(DBHelper.java:142)
at frm.Mainfrm.getworkeramount(Mainfrm.java:590)
at frm.Mainfrm.(Mainfrm.java:18)
at frm.Mainfrm.main(Mainfrm.java:666)
求大神请教