|
JDBC is a java database connectivity API that is a part of the java Enterprise APIs provided by Sun Microsystems. JDBC defines a set of API objects and method to interact with databases. Any java program that needs to access data from databases in a quick and efficient way must use JDBC. Though java provided plenty of classes and interfaces in its java.io package, the major drawback is that can be accessed through these must exist only in the form of streams.Hence, JDBC is a must for all java applications that data stored in external data providers like SQL Server, Oracle or Access.
Need for JDBC
The following reasons are:
-
ODBC uses a C interface. Calls from java to native Code have a number of drawback in the area of security, implementation, robustness, and automatic portability of application. This setback makes the ODBC driver inappropriate for direct use in a java application.
-
A literal translation of the ODBC C interface in to a java API would not be desirable.
-
ODBC mixes simple and advanced features to gather, and it has complex option even for simple queries.
-
JDBC is portable and secure on all java platform for network computer to mainframes.
-
JDBC is a standard interface for java programs to access relational databases.
JDBC Driver types
JDBC drivers are divided into four types or levels. Each type defines a JDBC driver implementation with increasingly higher levels of platform independence, performance, and deployment administration. The four types are:
-
Type 1: JDBC-ODBC Bridge
-
Type 2: Native-API/partly Java driver
-
Type 3: Net-protocol/all-Java driver
-
Type 4: Native-protocol/all-Java driver
Type 1: JDBC-ODBC Bridge: The JDBC-ODBC Bridge is a JDBC driver that implements JDBC operations by translating them into ODBC operations. To ODBC it appears as a normal application program. The Bridge implements JDBC for any database for which an ODBC driver is available. The Bridge is implemented as the sun.jdbc.odbc Java package and contains a native library used to access ODBC.
In order to use the JDBC-ODBC bridge you must have 3 things:
-
The JDBC-ODBC bridge driver that comes as part of java 2 platform
-
An ODBC driver
-
An ODBC data source
Type 2: Native-API/partly Java driver: The JDBC calls are converted in to calls on the client API for DBMS. This driver are uses java Native Interface that calls the local database APIs.This driver like the ODBC driver needs binary code on the client machine. This driver also requires the native database libraries to be installed and configured on the client's machine.
Type 3: Net-protocol/all-Java driver: This driver uses a networking protocol and middleware to communicate with the server. The server then translates this to a DBMS specific function calls. The specific protocol used depends on the vendor. This is most flexible JDBC alternative. Type 3 drivers do not require any native binary code and are database independent.
Type 4: Native-protocol/all-Java driver:The kind of driver converts JDBC calls into the network protocol like TCP/IP and other proprietary protocols used by DBMS directly. This allow a direct call from the client machine to the DBMS server and is a practical solution for Internet access.
JDBC Architecture
Java Program ---- JDBC Driver ---- Application Server ---- Database
|