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的时候就返回真,否则为假,不知道上面哪里有问题,谢谢了。
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的时候就返回真,否则为假,不知道上面哪里有问题,谢谢了。
解决方案 »
- 求指教,该程序为什么返回false?怎么改才会返回true
- Thread.currentThread()的疑问
- textarea 怎么设置成只读?
- jxl读取excel文件出现错误,请高手指点!
- 怎么把找到的int,放到一个list里面?arraylist好像只能放string啊,不用数组。
- 当线程的run中包含String[] list = string.split("_");语句时,线程无法用Thread.interrupt()中止,这是为何?
- GUI时的中文输入问题
- 关于james邮件服务器.请指点一二.
- Java该怎么学?
- Java基本类型和引用类型
- 自定义异常问题
- 为什么用java开发出的桌面程序感觉外观比较奇怪?
编译的时候就通不过。建议楼主看看ResultSet的API,之后就会明白了。
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类已足够满足你的要求了。