Guest User

Untitled

a guest
Apr 23rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. public void valueChanged(ListSelectionEvent e)      //Handle resultsList
  2.     {
  3.         Connection myConnection;        // Connection to the database
  4.         String Query;                        // String representation of the query to the database
  5.         Statement stmt;                      // Statement to execute the query in the database
  6.         ResultSet results;                  // ResultSet to store output of the database query
  7.        
  8.         if(e.getSource() == resultsList &&                      //An item is selected from resultsList that
  9.             resultsList.getSelectedIndex() < curIndex)      // is not empty
  10.         {
  11.             curStoreID =
  12.               Integer.parseInt(stores[resultsList.getSelectedIndex()].split(" ")[STORE_ID_INDEX]);
  13.            
  14.             custStoreID.setText(String.format("Store Number: %d", curStoreID));
  15.            
  16.             try
  17.             {
  18.                 // Load database client driver
  19.                 Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
  20.                
  21.                 // Connect to the database
  22.                 myConnection =
  23.                   DriverManager.getConnection("jdbc:derby://localhost:1527/stores_db", "root", "root");
  24.  
  25.                 // SQL CODE TO QUERY DATABASE FOR ADDRESS OF THE STORE WITH STORE_ID = curStoreID
  26.                 Query = "select s.address, zc.city, zc.state, s.zip from stores s" +
  27.                         " inner join zip_codes zc on s.zip = zc.zip where s.store_id = " + curStoreID;
  28.                 System.out.println(Query);
  29.                 stmt = myConnection.createStatement();
  30.                 System.out.println(1);
  31.                 results = stmt.executeQuery(Query);
  32.  //-----ERROR IS THE NEXT LINE
  33.                 address.setText(results.getString("address") + " " + results.getString("city") +
  34.                                 ", " + results.getString("state") + " " + results.getString("zip"));
  35.                 System.out.println(3);
Add Comment
Please, Sign In to add comment