JDBC  «Prev  Next »

Lesson 2What is JDBC?
ObjectiveDescribe how the JDBC interacts with the code and the database.

What is JDBC?

Describe how JDBC, Servlets and database can interact

JDBC stands for Java Database Connectivity, and it’s a set of classes and drivers that enable Java programs to access popular databases. It’s quite similar to Microsoft’s ODBC(Open Database Connectivity), in fact a JDBC-ODBC bridge makes it simple to use JDBC to access any database for which ODBC drivers exist.
The existence of the bridge has spared many database vendors the trouble of creating JDBC drivers for their database software – they expect you to use their ODBC driver and the bridge. The following image illustrates how Java, JDBC, the bridge, ODBC, a driver, and a database program work together:

How Java, JDBC, the bridge, ODBC, a driver and a database work together
How
  1. Java,
  2. JDBC,
  3. bridge,
  4. ODBC,
  5. a driver and
  6. database
work together

Main JDBC Advantage

The main advantage to using JDBC to access a database is that your code only needs to know about JDBC, no matter what kind of database you are trying to reach. JDBC code only needs to find the driver, which could be the bridge or a pure JDBC driver. The driver will pass the information on to the database program, but the bridge needs to pass the information on to the ODBC driver, and then to the database program (adding an extra step). In either case the driver knows exactly how to work with the database program. Pure JDBC drivers would probably be faster than using the bridge, but there aren't many pure JDBC drivers available. Learn how to use JDBC in the next lesson.