Wednesday, February 27, 2008

What is JDBC?

Java Database Connectivity (JDBC) is an API for the Java programming language that defines how a client may access a database. It provides methods for querying and updating data in a database. JDBC is oriented towards relational databases.

The Java Platform, Standard Edition includes the JDBC API together with an ODBC implementation of the API enabling connections to any relational database that supports ODBC. This driver is native code and not Java, and is closed source.

Overview
JDBC has been part of the Java Standard Edition since the release of JDK 1.1. The JDBC classes are contained in the java.sql package. Starting with version 3.0, JDBC has been developed under the Java Community Process. JSR 54 specifies JDBC 3.0, JSR 114 specifies the JDBC Rowset additions, and JSR 221 is the specification of JDBC 4.0.

JDBC allows multiple implementations to exist and be used by the same application. The API provides a mechanism for dynamically loading the correct Java packages and registering them with the JDBC Driver Manager. The Driver Manager is used as a connection factory for creating JDBC connections.

JDBC connections support creating and executing statements. These statements may be update statements such as SQL INSERT, UPDATE and DELETE or they may be query statements using the SELECT statement. Additionally, stored procedures may be invoked through a statement. Statements are one of the following types:

  • Statement – the statement is sent to the database server each and every time.
  • PreparedStatement – the statement is cached and the the execution path is pre determined on the database server allowing it to be executed multiple times in an efficient manner.
  • CallableStatement – used for executing stored procedures on the database.

Update statements such as INSERT, UPDATE and DELETE return an update count that indicates how many rows were affected in the database. These statements do not return any other information.

Query statements return a JDBC row result set. The row result set is used to walk over the result set. Individual columns in a row are retrieved either by name or by column number. There may be any number of rows in the result set. The row result set has metadata that describes the names of the columns and their types.

There is an extension to the basic JDBC API in the javax.sql package that allows for scrollable result sets and cursor support among other things.

Driver Types
There are commercial and free drivers available for most relational database servers. These drivers fall into one of the following types:

  • Type 1, the JDBC-ODBC bridge
  • Type 2, the Native-API driver
  • Type 3, the network-protocol driver
  • Type 4, the native-protocol drivers
  • Internal JDBC driver, driver embedded with JRE in Java-enabled SQL databases. Used for Java stored procedures.
  • JDBC URL, all Database Connection String

About this Terminology
This terminology is from The Wikipedia which is published under the GNU Free Documentation License.

0 comments: