Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void valueChanged(ListSelectionEvent e) //Handle resultsList
- {
- Connection myConnection; // Connection to the database
- String Query; // String representation of the query to the database
- Statement stmt; // Statement to execute the query in the database
- ResultSet results; // ResultSet to store output of the database query
- if(e.getSource() == resultsList && //An item is selected from resultsList that
- resultsList.getSelectedIndex() < curIndex) // is not empty
- {
- curStoreID =
- Integer.parseInt(stores[resultsList.getSelectedIndex()].split(" ")[STORE_ID_INDEX]);
- custStoreID.setText(String.format("Store Number: %d", curStoreID));
- try
- {
- // Load database client driver
- Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
- // Connect to the database
- myConnection =
- DriverManager.getConnection("jdbc:derby://localhost:1527/stores_db", "root", "root");
- // SQL CODE TO QUERY DATABASE FOR ADDRESS OF THE STORE WITH STORE_ID = curStoreID
- Query = "select s.address, zc.city, zc.state, s.zip from stores s" +
- " inner join zip_codes zc on s.zip = zc.zip where s.store_id = " + curStoreID;
- System.out.println(Query);
- stmt = myConnection.createStatement();
- System.out.println(1);
- results = stmt.executeQuery(Query);
- //-----ERROR IS THE NEXT LINE
- address.setText(results.getString("address") + " " + results.getString("city") +
- ", " + results.getString("state") + " " + results.getString("zip"));
- System.out.println(3);
Add Comment
Please, Sign In to add comment