Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I get this program to also print the first entry in the list too?
    primarykey
    data
    text
    <p>I can't display the first entry from my query that returns multiple answers. For example, a search with a result set of five will return the second to fifth and miss the first entry. If I search for something that has one entry as output it doesn't return anything but just hangs because it is the first and only entry in the database. When I debug it and search for something that I know has only one entry in the DB, it goes to line 12 then 15 then 25. How can I modify the loop to include the first entry to be printed also?</p> <p>CODE:</p> <pre><code>try { ResultSet rs; String comparex = jTextField2.getText().trim().toUpperCase();// puts the textfield into a string object rs = stmt.executeQuery( "SELECT * FROM BASTIMP where DETAILS like '%"+comparex+"%'" ); //paradox equivalent '..comparex..' String amount; String date; String attached = ""; if (rs.next()) // **Line 12** { }else { DisplayAreaX.setText("ENTER VALID VENDOR"); } while (rs.next()) { // **Line 15** String details = rs.getString("DETAILS"); //get results from DETAILS date = rs.getString ("DATE PAID"); //CORRECT? amount = rs.getString ("AMOUNT BANK"); attached = attached + details +":"+ '\n'+ "Date " +date+ " / "+ "Amount £"+ amount+ '\n'; // - ADDS MULTIPLE ENTRIES ON OUTPUT OF jList! DisplayAreaX.setText(attached); System.out.println(details+":"+ '\n'+ "Date "+date+ " / "+ "Amount £"+ amount+ '\n'); } } catch (SQLException e) { System.out.println("SQL Exception: " + e.toString()); } catch (ClassNotFoundException cE) { System.out.println("Class Not Found Exception: " + cE.toString()); } // **Line 25** </code></pre> <p>Thanks </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload