(1) String sqlcmd="SELECT * FROM sale WHERE id="+chekid+""; ResultSet rs=ObjC.executeQuery(sqlcmd); if(rs==null||!rs.next()) //结果集为空 { out.print("提示语句"); }(2) String sqlcmd="SELECT * FROM sale WHERE id="+chekid+""; ResultSet rs=ObjC.executeQuery(sqlcmd); finaly(){out.print("11111111");}
为什么我这么写,就算有能查到的数据,也会执行 if(myResultSet==null||!myResultSet.next()) //结果集为空 { chekJTextField.setText("对不起没有查询的数据"); chekJTextField.setBackground(Color.pink); } try { myResultSet = myStatement.executeQuery("SELECT * FROM sale WHERE id="+chekid+""); // while (myResultSet.next()) {
String sqlcmd="SELECT * FROM sale WHERE id="+chekid+"";
ResultSet rs=ObjC.executeQuery(sqlcmd);
if(rs==null||!rs.next()) //结果集为空
{
out.print("提示语句");
}(2)
String sqlcmd="SELECT * FROM sale WHERE id="+chekid+"";
ResultSet rs=ObjC.executeQuery(sqlcmd);
finaly(){out.print("11111111");}
{
chekJTextField.setText("对不起没有查询的数据");
chekJTextField.setBackground(Color.pink);
} try {
myResultSet = myStatement.executeQuery("SELECT * FROM sale WHERE id="+chekid+"");
// while (myResultSet.next()) {
// datefrom=new java.sql.Date(fy,fm,fd);
String time=myResultSet.getString("day") ;
datet=time.substring(0,10);
namet=myResultSet.getString("name") ;
hospitalt=myResultSet.getString("hospital") ;
backt=myResultSet.getString("back") ;
profitt=myResultSet.getString("profit") ;
salet=myResultSet.getString("sale") ;
dipdata();
}
if(myResultSet==null||!myResultSet.next()) //结果集为空
{
chekJTextField.setText("对不起没有查询的数据");
chekJTextField.setBackground(Color.pink);
}
myResultSet.close();
}
catch ( SQLException sqlex ) {
updateJButton.setEnabled(false);
}
}
而你又在 while( )后面执行这条-》 if(myResultSet==null||!myResultSet.next()) 当然就会执行咯
你把 if(myResultSet==null) 放到whiel()上面判断