Wednesday, October 1, 2014

2.2 JDBC Architecture


2.2 JDBC Architecture

-          The JDBC API supports both two-tier and three-tier processing models for database access.
-          This interface makes it easy to access a database because it provides an abstract layer that hides the low-level details
-          It also provides for interoperability and portability.
-          It allows a single application to access multiple database management systems simultaneously. 

-          For example : 
1)      A  single application can query and manipulate
§  Database in Oracle and
§  Database in DB2. 

2)      Communication with a database management system (DBMS) is through method calls. 
3)      These calls are passed to the driver.
4)      Which in turn, translates them into DBMS-specific calls.
5)      The driver basically acts like a set of library routines.
6)      Therefore, to get wer program to communicate with a particular DBMS.
7)      We need a compatible JDBC driver.

1)    Two-tier Processing Models :
-          In the two-tier model, a Java applet or application talks directly to the data source.
-          This requires a JDBC driver.
-          That can communicate with the particular data source being accessed.
-          A user's commands are delivered to the database or other data source.
-          And the results of those statements are sent back to the user.
-          The data source may be located on another machine.
-          To which the user is connected via a network.

-          This is referred to as a client/server configuration.
1)      User's machine as the client
2)      And the machine housing the data source as the server.



[Figure: Two-tier Architecture for Data Access.]

2)    Three-tier Processing Models :
-         In the three-tier model, commands are sent to a "middle tier" of services.
-         Which then sends the commands to the data source.
-         The data source processes the commands.
-         And sends the results back to the middle tier.
-         Which then sends them to the user.
-         Middle tier makes it possible to maintain control over access.
-         And the kinds of updates that can be made to corporate data.
-         Another advantage is that it simplifies the deployment of applications.
-         The three-tier architecture can provide performance advantages.

-         Middle tier has often been written in languages. such as
1)      C or
2)      C++

-         Offer fast performance.
-         The introduction of optimizing compilers that translate Java bytecode into efficient machine-specific code.
-         And technologies such as Enterprise JavaBeans™, the Java platform is fast becoming the standard platform for middle-tier development.
-         This is a big plus, making it possible to take advantage of Java's :
1)      robustness,
2)       multithreading, and
3)      security features.

-         Robustness, multithreading, and security features.
-         With enterprises increasingly using the Java programming language for writing server code, the JDBC API is being used more and more in the middle tier of a three-tier architecture.
-         Some of the features that make JDBC a server technology are its support for connection :
1)      Pooling,
2)      Distributed transactions, and
3)      Disconnected rowsets.


[Figure: Three-tier Architecture for Data Access.]
-         But in general JDBC Architecture consists of two layers:
1)    JDBC API:
§  This provides the application-to-JDBC Manager connection.

2)    JDBC Driver API:
§  This supports the JDBC Manager-to-Driver Connection.

-         The JDBC API uses a driver manager and database-specific drivers.
-         To provide transparent connectivity to heterogeneous (mixed) databases.
-         The JDBC driver manager ensures that the correct driver is used to access each data source.
-         The driver manager is capable of supporting multiple concurrent drivers connected to multiple heterogeneous (mixed) databases.
-         Following is the architectural diagram, which shows the location of the driver manager with respect to the JDBC drivers and the Java application:




[Fig:- JDBC Architecture]


-         The JDBC API provides the following interfaces and classes:

1)    DriverManager:
§  This class manages a list of database drivers.
§  Matches connection requests from the java application with the proper database driver using communication sub-protocol.
§  The first driver that recognizes a certain sub-protocol under JDBC will be used to establish a database Connection.

2)    Driver:
§  This interface handles the communications with the database server.
§  We will interact directly with Driver objects very rarely.
§  Instead, we use DriverManager objects, which manages objects of this type.
§  It also abstracts the details associated with working with Driver objects.

3)    Connection :
§  This interface with all methods for contacting a database.
§  The connection object represents communication context
§  For example :
·        All communication with database is through connection object only.
4)    Statement :
§  We use objects created from this interface to submit the SQL statements to the database.
§  Some derived interfaces accept parameters in addition to executing stored procedures.

5)    ResultSet:
§  These objects hold data retrieved from a database after we execute an SQL query using Statement objects.
§  It acts as an iterator to allow we to move through its data.

6)      SQLException:
§  This class handles any errors that occur in a database application.

-         The primary packages for JDBC.
1)    java.sql and
2)    javax.sql

*    The basic steps to get wer program up and running are:

1)      Load the driver and register it with the driver manager
2)      Connect to a database
3)      Create a statement
4)      Execute a query and retrieve the results, or make changes to the database.
5)      Disconnect from the database.

-          Steps 1 and 2 are the only DBMS-specific steps.
-          The rest is DBMS independent.
-          JDBC is very powerful and flexible.

No comments:

Post a Comment