«^»
4.4. How do you use JDBC?

A Java program that wants to use JDBC to access a database server will normally consists of the following steps:

  1. Use the getConnection method (of the class java.sql.DriverManager) to establish a connection to a database.
  2. Use the createStatement, prepareStatement or prepareCall method.
  3. For the prepareStatement and prepareCall methods, use calls of setXXX methods to establish any parameters that are needed by the statement.
  4. Use execute, executeQuery or executeUpdate to execute the statement.
  5. If the statement is a query, process the result set that is returned.
  6. Close the statement.
  7. Do steps 2 to 6 for each statement you wish to process.
  8. Close the connection that was established by getConnection.
By default, all the SQL statements will automatically be committed: this is called autocommit mode. However, you can disable this and execute calls of commit or rollback yourself.