1 Reply Latest reply: May 3, 2008 11:38 PM by 3004 RSS

    jdbc select statement


      I got :
      String unitNum="select * from unitList where unitNum='"+unitNum_txt+"';";  
      //unitList is the table,search field name is unitNum
                       Statement stmt=con.createStatement();
                      ResultSet rs = stmt.executeQuery(unitNum);  
      If the unitList table has the record..the details are printed out.But if the table doesn't have it,what code do i write to detect it?In my sql ,the statement will return empty set.

      what java code would detect ,no record found?

      Hope someone could guide me out.

        • 1. Re: jdbc select statement
          If there are no rows returned, the body of the while loop will never be entered. You don't need to do anything special.

          If you wnat to explicitly note that no rows were returned, you could do something like this:
          boolean rowsReturned = false;
          while (rs.next()) {
            rowsReturned = true;
            // process current row
          if (rowsReturned) {
            // rows were returned
          else {
            // no rows were returned