OCP Prep Notes On JDBC

Absolutely Needed:

  • Changes to DB are ordinarily made with INSERT, UPDATE or DELETE SQL stats, not thru a result set (although it is also possible)
  • JDBC automatically closes the ResultSet when you run another SQL statement from the same Statement
  • Vendor DBs contain Statement, ResultSet and Connection implementations
  • Starting with JDBC 4.0, Java applications can automatically load and register the drivers
  • Calling absolute(1) is the same as calling first(); calling absolute(-1) is the same as calling last()
  • All execution methods in the Statement interface implicitly close the currently open ResultSet


  • Methods other than next() require the ResultSet be SCROLLABLE (by declaring something like

Statement stmt = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

  • Calling the method relative(1) is identical to calling the method next() and calling the method relative(-1) is identical to calling the method previous().
  • conn, stat and rs are created without new
  • conn.createStatement(int, int) accepts int resultSetType, int resultSetConcurrency – in this order
  • Does main() declare throws? if not, could be a comperr if there’s no TCF
  • ResultSet‘s getTimestamp(int columnIndex) return date + time up to seconds
  • ResultSet has only TWO methods with ‘after’ and ‘before’ in them: void beforeFirst() and void afterLast() à they can’t be used in sout
  • For prep practice: file URL on Windows needs THREE slashes: file:///C:/some_dir/some_file.txt
  • For prep practice: DB can be accessed by stating regular path:
String url = "jdbc:derby:C:/Try_Java/zoo";

Setting Up A DB for OCP Practice is covered here

Leave Comment

Your email address will not be published.