百合川さら下马番号:关于if(rs==null)的一个实例的问题,拜托了
来源:百度文库 编辑:神马品牌网 时间:2024/05/03 05:07:04
代码如下:
String strSQL="select * from tPlan
where fTime < #"+R+"# and fStyle='"+C+"'";
ResultSet rs = s.executeQuery(strSQL);
if(rs==null){
JOptionPane.showMessageDialog(null, "找不到所需!");
//不知道为什么不显示//
}
R和C一个是用以表示时间的字符串,另一个是用以表示名城的字符串
但是就算查询不到结果也不会弹出提示
还望各路大侠替小弟解答
String strSQL="select * from tPlan
where fTime < #"+R+"# and fStyle='"+C+"'";
ResultSet rs = s.executeQuery(strSQL);
if(rs==null){
JOptionPane.showMessageDialog(null, "找不到所需!");
//不知道为什么不显示//
}
R和C一个是用以表示时间的字符串,另一个是用以表示名城的字符串
但是就算查询不到结果也不会弹出提示
还望各路大侠替小弟解答
应该是rs抛出异常了,应在catch语句里捕获处理一下:
try{....}
catch(Exception e) { ....}
if(rs==null)的写法没错.
应该是 if(not IsObject(rs)){ 吧