22.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 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 Web Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.