18.1. Basic Steps in Using JDBC

There are seven standard steps in querying databases:

1.
Load the JDBC driver.
2.
Define the connection URL.
3.
Establish the connection.
4.
Create a statement object.
5.
Execute a query or update.
6.
Process the results.
7.
Close the connection.

Here are some details of the process.

Load the Driver

The driver is the piece of software that knows how to talk to the actual database server. To load the driver, all you need to do is to load the appropriate class; a static block in the class itself automatically makes a driver instance and registers it with the JDBC driver manager. To make your code as flexible as possible, it is best to avoid hard-coding the reference to the class name.

These requirements bring ...

Get Core Servlets and JavaServer Pages™ now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.