Created
July 29, 2011 08:05
-
-
Save prisoner/1113421 to your computer and use it in GitHub Desktop.
The try-with-resources Statement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void viewTable(Connection con) throws SQLException { | |
String query = "select COF_NAME, SUP_ID, PRICE, SALES, TOTAL from COFFEES"; | |
try (Statement stmt = con.createStatement()) { | |
ResultSet rs = stmt.executeQuery(query); | |
while (rs.next()) { | |
String coffeeName = rs.getString("COF_NAME"); | |
int supplierID = rs.getInt("SUP_ID"); | |
float price = rs.getFloat("PRICE"); | |
int sales = rs.getInt("SALES"); | |
int total = rs.getInt("TOTAL"); | |
System.out.println(coffeeName + ", " + supplierID + ", " + price + | |
", " + sales + ", " + total); | |
} | |
} catch (SQLException e) { | |
JDBCTutorialUtilities.printSQLException(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment