比较数据库中两个数值的大小--在线等,先谢谢过来的哥们
public boolean Compare(){
Connection con = null;
PreparedStatement ps = null;
ResultSet rs=null;
boolean exist=false;
try{
con = DriverManager.getConnection(url);
String selectStr = "select usermax,usernum from userlimit";
ps = con.prepareStatement(selectStr);
rs=ps.executeQuery();
if(usermax>usernum)
exist=true;
System.out.println("比较");
}
catch(SQLException exc){
exc.printStackTrace();
}
return exist;
}
}
我想实现usermax>usernum的时候就返回真,否则为假,不知道上面哪里有问题,谢谢了。
问题点数:36、回复次数:3Top
1 楼cuilichen(fjfjfjfj)回复于 2005-06-01 12:19:16 得分 10
在上面的程序中,你得到了resultSet,但是没有使用它。
同时usermax和usernum两个参数没有定义。
编译的时候就通不过。
建议楼主看看ResultSet的API,之后就会明白了。Top
2 楼enrico(小甭)回复于 2005-06-01 12:29:39 得分 4
楼上说得很清楚Top
3 楼irvine007(┣━┫Rvine)回复于 2005-06-01 14:05:47 得分 22
public boolean Compare(){
Connection con = null;
PreparedStatement ps = null;
ResultSet rs=null;
boolean exist=false;
try{
con = DriverManager.getConnection(url);
String selectStr = "select usermax,usernum from userlimit";
ps = con.prepareStatement(selectStr);
rs=ps.executeQuery();
// ------------------------------
int usermax, usernum;
if (rs.next()) {
usermax = rs.getInt("usermax");
usernum = rs.getInt("usernum");
if (usermax > usernum)
exist = true;
} exist=true;
System.out.println("比较");
}
catch(SQLException exc){
exc.printStackTrace();
}
return exist;
}
}
// 而且以上代码,既然没有使用参数就不要PrepareStatement
// 增加开销不是。Statement类已足够满足你的要求了。Top




