("SELECT * FROM sale WHERE id="+chekid+"");
如果我执行的这个语句没有查找到相应的数据
我想有个提示语句
怎么处理这个提示语句呢
我试过 catch ( SQLException sqlex )这里处理是没有用的

解决方案 »

  1.   

    (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");}
      

  2.   

    为什么我这么写,就算有能查到的数据,也会执行 if(myResultSet==null||!myResultSet.next())   //结果集为空
    {
          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);
            
            
             }
          }
      

  3.   

    因为你只有一条记录,在你while(rs.next())已经执行了一次了,
    而你又在 while( )后面执行这条-》 if(myResultSet==null||!myResultSet.next())  当然就会执行咯
    你把 if(myResultSet==null)  放到whiel()上面判断