|
[Exercise | API Docs | Short Course| Exercises] Help is available for each task. Task 1Query the data, using the SQL SELECT statement, in descending order by the JJJJData column Cups and obtain a ResultSet.
ResultSet result = stmt.executeQuery(
"SELECT Entry, Customer, DOW, Cups, Type " +
"FROM JJJJData " +
"ORDER BY Cups DESC");
Task 2Determine if at least one row was returned. If so, the first row contains the information regarding the customer who drank the most coffee in one day. Use the ResultSet.getXXX methods to store the column data into program variables. Print "On (DOW) 4J Customer (Customer) consumed the most coffee. Cups: (Cups), Type: (Type)." Set the Cups total to the initial Cups column value.
Task 3While the ResultSet contains more data, move through each row. Use the ResultSet.getXXX methods to store the column data into program variables. Add the current Cups column value to the Cups total. Print all column data for the row.
Task 4Print the total cups of coffee consumed. Close the Statement and the Connection.
A ResultSet is automatically closed when its associated Statement is closed. In addition, the current ResultSet is closed when a new Statement.execute method, of any variety, is invoked. Even so, it is good practice to close a ResultSet when you are finished with it. This was not done here, because the program essentially obtained the ResultSet, operated on the data as we got it, then closed the Statement and ended the program. Copyright 1996-2000 jGuru.com. All Rights Reserved. | |||||||||||
|
| ||||||||||||