1. Technology

JDBC Overview

By

See More About

There are many different databases that you could choose to use with Java. As you might expect each of these databases likes to be talked to in a slightly different way. The creators of the databases all have their own way of doing things and for a programming language like Java that means there needs to be a degree of flexibility in how Java connects to a database. This is great for Java developers who don't just have to rely on the Derby database.

This is achieved by the JDBC API. It enables Java to talk to connect to a database (or similar data source), send SQL commands to manipulate the data in the database, and be able to process the results of the SQL commands.

The JDBC API

The JDBC API is built for Java developers writing Java applications and for database vendors who want to write a database driver to enable Java to talk to their database.

The JDBC Driver API

The JDBC Driver API is one that most Java developers will never concern themselves with. It was designed and built for database vendors  and those who create database tools. It's a low-level API which enables the database vendors and tool creators to create their own database drivers. This means their databases or tools will be able to plug-in to and take advantage of the JDBC. This flexibility allows Java the ability to talk to any database that has a third-party database driver created for it.

The JDBC API

This part of the API is designed with Java applications programmers in mind. There are four types of drivers associated with the JDBC API:

  • Type 1: JDBC-ODBC Bridge plus ODBC Driver - Here the driver will talk to the database by using an ODBC driver. A translation happens so that the JDBC understands and has access to the database. There is a default JDBC-ODBC provided but it's not intended for anything more than experimental or last resort cases. There are many ODBC driver available for use instead.
  • Type 2: A native API partly Java technology-enabled driver - This kind of database driver is partially written in Java and partially written in native code. This means some binary code relating to the client is installed.
  • Type 3: Pure Java Driver for Database Middleware - This type of driver translates JDBC calls to the vendor's protocol, which is then subsequently changed into  a DBMS protocol by a middleware server. This enables the middleware server to provide connectivity to many different databases.
  • Type 4: Direct-to-Database Pure Java Driver - The direct to database driver converts JDBC calls into the network protocol used directly by the database. This means  a direct call is placed from the client's machine to the DBMS server. Useful for Intranet access.

Advantages of the JDBC API

There is a lot of leverage to be had with this model of the JDBC API. Third parties can supply database drivers for any database. There are even some database drivers out there that are better than the ones supplied by the actual database vendor. This kind of flexibility can only be good for the Java application programmer.

The developers of Java applications have the advantage of not having to worry how Java talks to the database. All they have to do is use the API in their programs. And, with the SQL language being an industry standard for databases it means that most programmers already know how to access and manipulate data in a database using it. This makes using the JDBC API pretty efficient for Java developers.

The JDBC API also provides full access to database metadata meaning that not only the data in the database it changeable but how it is stored is to.

  1. About.com
  2. Technology
  3. Java
  4. Building Applications
  5. Working With Databases
  6. JDBC Overview

©2014 About.com. All rights reserved.