Java Tutorial · Revision notes

Java JDBC

JDBC (Java Database Connectivity) is the standard Java API in java.sql for talking to relational databases. This chapter explains what JDBC is, the four driver types, the steps to connect and run SQL, and why PreparedStatement is better than Statement.

Quick revision

  • JDBC = java.sql API; DriverManager → Connection → Statement → ResultSet
  • Types: 1 ODBC bridge (removed), 2 native, 3 middleware, 4 thin pure Java
  • Steps: driver, connection, statement, execute, process, close
  • executeQuery → ResultSet; executeUpdate → int; indexes start at 1
  • PreparedStatement: precompiled, ? params, injection-safe, batching
  • Use try-with-resources; transactions via setAutoCommit(false)/commit/rollback
Read the full Java JDBC notes on Doubtclip →