Turn Desktop View Off
by Dinesh Thakur

JDBC defines an API designed to support basic SQL functionality independent of any specific SQL implementation. This means the focus is on executing SQL statements and retrieving their results.

JDBC is an international standard for programming access to SQL databases. It was developed by JavaSoft, a subsidiary of Sun Microsystems.

      Relational Database Management System supports SQL. As we know that Java is platform independent, JDBC makes it possible to write a single database application that can run on different platforms and interact with different Database Management Systems.

       Java Database Connectivity is similar to Open Database Connectivity (ODBC) which is used for accessing and managing database, but the difference is that JDBC is designed specifically for Java programs, whereas ODBC is not dependent upon any language.

       In short, JDBC helps the programmers to write Java applications that manage these three programming activities:

• Establishing a connection with a database or other tabular data source

• Sending SQL commands to the database

• Processing the results

Java Database Connectivity or in short JDBC is a technology that enables the Java program to manipulate data stored in a database. JDBC is a Java programming interface that allows the Java program to access database management system from Java code. It was developed by JavaSoft, a subsidiary of Sun Microsystem.

     JDBC is similar to Micro ODBC interface to SQL database which is used for accessing and managing database. However, the difference is that while JDBC is specifically for Java program, ODBC is not dependent upon any language.

In short, JDBC helps the programmer to write Java applications that manage three programming activities.

1. It helps us to connect to data source like database.

2. It helps us to send queries and update statements to the database.

3. It helps us to restore and process the results it receives from the database in terms of answering your queries.

JDBC Versions

i. JDBC 1.0 API

ii. JDBC 1.2 API

iii. JDBC 2.0 optional package API

iv. JDBC 2.1 core API

v. JDBC 3.0 API

vi. JDBC4.0 API

Feature of JDBC 1.0 API

The JDBC 1.0 API was the first officially JDBC launched. It consisted of the following

Java classes:

Features of JDBC 1.2 API

i. It supports updatable ResultSets.

ii. New pass through scheduler for increased performance.

Features of JDBC 2.1 CORE API

i. Scrolls forward and backward Results or has ability to move to a specific row.

ii. We can use multiple SQL statements in database as a unit or batch.

Features of JDBC 3.0 API

i. A new concept has been added to API, that of SavePoint.

ii. DatabaseMetaData API has been added.

iii. Connection pool.

Features of JDBC 4.0

i. Auto-loading of JDBC driver class.

ii. SQL XML support.

JDBC Driver Model

JDBC supports two-tier and three-tier model:

I. Two-tier Model

In this model the Java applets and application are directly connected with any type of database. The client directly communicates with database server through JDBC driver.

                    Two-tier Model

As another layer, the Manager should communicate with various third party drivers that actually connect to the database and return information from the query or perform action specified by the query.

II. Three-tier Model

In this model, client connects with database server through a middle-tier server, which is used for various purposes. Middle-tier server performs various functions.

                  Three-tier Model

It extracts the SQL command from the client and sends these commands to the database server. Also, it extracts the result from the database server and submits the same to the client.

Exploring JDBC Architecture

JDBC is open specification given by Sun Microsystems having rules and guidelines to develop JDBC driver. JDBC driver is a bridge software between Java application and database software. It converts Java call to database call and vice versa. Java application talks with database server using JDBC driver.

              Exploring JDBC Architecture

• JDBC call converts database call.

• JDBC driver connects to database server and sends command to the database server.

• Database executes the statement.

• Sends the output back to JDBC driver.

• JDBC driver sends back to java application.

 Each JDBC driver is specific to one database software.

We can get the JDBC driver from three parties:

1. Sun Microsystems

2. Database vendor

3. Third party vendor

It is recommended to use database vendor- supplied JDBC drivers.

Non-Java applications use ODBC drivers to interact with database software.

     There are four different methodologies or mechanisms to develop JDBC drivers based on the rules and guidelines of JDBC specification. These are:

i.   Type-1(JDBC-ODBC Bridge Driver)

ii. Type-n Native API/ partly Java Driver)

iii. Type-3(Net-Protocol/All Java Driver)

iv. Type-4(Native- Protocol/All Java Driver)

 

i. Type-l(JDBC-ODBC Bridge Driver)

The type-1 mechanism-based drivers are given drivers to take the support of ODBC drivers while introducing to database software. In this process, the type 1 driver takes support of the native code to communicate with ODBC drivers.

                 Type-l (JDBC-ODBC Bridge Driver)

JDBC Type-1 driver is not specific to any database software because it does not interact with database software directly. It interacts with database software by using the database software-specific ODBC driver.

      Type-1 driver is supplied only by Sun Microsystems. It has a built-in JDK software. JDK software supplies a basic and built-in service called DriverManager which serves to manage a set of JDBC drivers and to establish the connection with database software by using JDBC driver.

Type-1 driver class name is: sun.jdbc.odbc.JdbcOdbcDriver

      Every JDBC driver must be registered with DriverManager service, as this creates JDBC class object in DriverManager service.

Advantages of JDBC-ODBC Bridge Driver

• Serves as a single driver that can be used to interact with different data stores.

• Allows you to communicate with all the databases supported by the ODBC driver.

• Represents a vendor-independent driver and is available with JDK

Disadvantages of JDBC-ODBC Bridge Driver

• Decreases the execution speed due to more number of transactions. (Include JDBC ODBC DB Native call)

• Depends on the ODBC driver due to which Java application indirectly becomes dependent on ODBC drivers.

ii. Type-2(JAVA to Native API)

Type-2 driver converts JDBC calls in a client machine. It uses native code to communicate with vendor database library. These native codes are usually written in C or C++.

                       Type-2 (JAVA to Native API)

Type-2 JDBC driver takes the support of vendor database software. In the figure, the java application is programmed using JDBC API, making JDBC calls. These JDBC calls are then converted into database specific native calls and the request is then dispatched to the database specific native libraries.

      Type-2 drivers are suitable to use with server-side application. It is not recommended to use type-2 drivers with client-side application since native libraries for the client platform should be installed on the client machines.

Advantages of Type-2 driver

• No need of working with ODBC

• Serves as the fastest driver compared to other types of drivers_

• Allows you to use the additional features provided by the specific database vendors to access the database which are even supported by JDBC specification.