Java JDBC PreparedStatement – Select Records Example

Steps to process Select SQL statement with JDBC

  1. Establishing a connection.
  2. Create a statement.
  3. Execute the query.
  4. Using try-with-resources Statements to Automatically Close JDBC Resources

From JDBC 4.0, we don’t need to include ‘Class.forName()’ in our code, to load JDBC driver. When the method ‘getConnection’ is called, the ‘DriverManager’ will automatically load the suitable driver among the JDBC drivers that were loaded at initialization and those loaded explicitly using the same class loader as the current application.

Any JDBC 4.0 drivers that are found in your classpath are automatically loaded. (However, you must manually load any drivers prior to JDBC 4.0 with the method Class.forName.)