Note that there are some explanatory texts on larger screens.

plurals
  1. POjava jdbc connection - result set output problems
    primarykey
    data
    text
    <p>I am currently trying to implement a jdbc connection that returns all the data in a table when i "search" for anything that matches the input with '%input%'.</p> <p>eg <code>ResultSet rs4 = stm4.executeQuery("select imageTime from image_data where imageName like '%" + value3 + "%' or imageTime like '%" + value3 + "%' or imageLocation like '" + value3 + "'" );</code></p> <p>i am trying to return ALL the rows in the result set as search results. but if i have Resultset.next commanded when there is no more rows to go to it causes the following results sets to all null,....</p> <p>if anything id love a method to output the entire result set, thanks.</p> <p>EDIT editing the question: to be more direct; i need a way to get every piece of data from each row in each containing column of the result set. so i can output it. This is my attempt of this below.</p> <p>rs4 = a Resultset as declared below.</p> <p>here is my code;</p> <pre><code>if(name_time_location == 1) { String value3=searchInput.getText();//Sets the search Input as value3 // selecting the cominbation from table, that match input options try{ con = DriverManager.getConnection("jdbc:mysql:blah blah"); // Query the database for the correct username and passord Statement stm3 = con.createStatement(); Statement stm4 = con.createStatement(); Statement stm5 = con.createStatement(); //queries database for password from input username ResultSet rs3 = stm3.executeQuery("select imageName from image_data where imageName like '%" + value3 + "%' or imageTime like '%" + value3 + "%' or imageLocation like '" + value3 + "'" ); //ResultSetMetaData rsmd = rs3.getMetaData(); //stm3.setFetchSize(5); //rs3.last(); //int numberOfRows = rs3.getRow(); //String[] resultList; //resultList = new String[numberOfRows]; // Fetch each row from the result set rs3.beforeFirst(); while(rs3.next()) { imageSearchResult1 = rs3.getString(1); rs3.next(); imageSearchResult11 = rs4.getString(1); rs3.next(); imageSearchResult12 = rs4.getString(1); rs3.next(); imageSearchResult13 = rs4.getString(1); rs3.next(); imageSearchResult14 = rs4.getString(1); }rs3.close(); }catch (Exception e) { //System.out.println("Exception: " + e + ""); } System.out.println("Search Results: \nName: " + imageSearchResult1 + " Time stamp: " + imageSearchResult2 + " Location: " + imageSearchResult3 + "\n" + "Name: " + imageSearchResult11 + " Time stamp: " + imageSearchResult21 + " Location: " + imageSearchResult31 + "\n" + "Name: " + imageSearchResult12 + " Time stamp: " + imageSearchResult22 + " Location: " + imageSearchResult32 + "\n" + "Name: " + imageSearchResult13 + " Time stamp: " + imageSearchResult23 + " Location: " + imageSearchResult33 + "\n" + "Name: " + imageSearchResult14 + " Time stamp: " + imageSearchResult24 + " Location: " + imageSearchResult34 + "\n" ); </code></pre>
    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.
    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