Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PreparedStatement ps =
- conn.prepareStatement( "SELECT i.*, j.* FROM Omega i, Zappa j WHERE i.name = ? AND j.num = ?" );
- try {
- // In the SQL statement being prepared, each question mark is a placeholder
- // that must be replaced with a value you provide through a "set" method invocation.
- // The following two method calls replace the two placeholders; the first is
- // replaced by a string value, and the second by an integer value.
- ps.setString(1, "Poor Yorick");
- ps.setInt(2, 8008);
- // The ResultSet, rs, conveys the result of executing the SQL statement.
- // Each time you call rs.next(), an internal row pointer, or cursor,
- // is advanced to the next row of the result. The cursor initially is
- // positioned before the first row.
- ResultSet rs = ps.executeQuery();
- try {
- while ( rs.next() ) {
- int numColumns = rs.getMetaData().getColumnCount();
- for ( int i = 1 ; i <= numColumns ; i++ ) {
- // Column numbers start at 1.
- // Also there are many methods on the result set to return
- // the column as a particular type. Refer to the Sun documentation
- // for the list of valid conversions.
- System.out.println( "COLUMN " + i + " = " + rs.getObject(i) );
- } // for
- } // while
- } finally {
- try { rs.close(); } catch (Throwable ignore) { /* Propagate the original exception
- instead of this one that you may want just logged */ }
- }
- } finally {
- try { ps.close(); } catch (Throwable ignore) { /* Propagate the original exception
- instead of this one that you may want just logged */ }
- } // try
Advertisement
Add Comment
Please, Sign In to add comment