SE452: Using JDBC [5/12] Previous pageContentsNext page

JDBC classes/interfaces are in two packages:

To use JDBC in your program:

  1. Load the JDBC Driver
  2. Establish the connection (or get the Connection from the DataSource)
  3. Send SQL Statements
  4. Process results
  5. Close the connection (and other resources)

For most server applications, we use Connection pools that are mapped to a javax.sql.DataSource. So the steps involve:

  1. Define the connection pool (driver and database)
  2. Lookup the DataSource using JNDI
  3. Obtain a connection from the DataSource
  4. Send SQL Statements
  5. Process results
  6. Close the connection (and other resources)

It is important to be aware of the resources that you are using when writing a JDBC program. You need to explicitly close connections, statements, etc.

Previous pageContentsNext page