java.sql.Connection db = null;
java.sql.Statement stmt = null;
java.sql.ResultSet rs = null;
try {
    // Obtain database connection
    // prepare statement
    // execute statement
    // Retrieve results
} catch(java.sql.SQLException e) {
  System.err.println(/* error message */);
  e.printStackTrace();
  throw e;
} finally {
  if(rs!=null)
     try { rs.close(); }
     catch(java.sql.SQLException e) {}
  if(stmt!=null)
     try { stmt.close(); }
     catch(java.sql.SQLException e) {}
  if(db!=null) { /* Release connection */ }
}

Example 1: Skeleton JDBC request.

Back to Article