Monday, November 12, 2012

Java databse connectivity in weblogic

What is JDBC ?
JDBC is an Java API for accessing Database in a uniform way...

what it providing ?
It's a platform Independent and location transperency its supports 2-tier and 3-tier also

JDBC Archtecture



Look once the Archetecture...

JDBC Architecture
The JDBC Architecture mainly consists of two layers:
First is JDBC API, which provides the application-to-JDBC Manager connection.
Second is JDBC Driver API, which supports the JDBC Manager-to-Driver Connection. This has to provide by the vendor of database, you must have notice that one external jar file has to be there in class path for forth type of driver.
The JDBC API uses a driver manager and database-specific drivers to provide transparent connectivity to heterogeneous 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 databases.
The top level layer in this model is the Java application. Java applications are portable. You can run a Java application without modification on any system that has a Java runtime environment installed. A Java application that uses JDBC can talk to many databases with some modifications. Like ODBC, JDBC provides a consistent way to connect to a database, execute commands, and retrieve the results. Also like ODBC, JDBC does not enforce a common command language. You can use Oracle-specific syntax when connected to an Oracle server and My SQL specific syntax when connected to a My SQL database.
The JDBC DriverManager
The JDBC DriverManager class is responsible for locating a JDBC driver needed by the application. When a client application requests a database connection, the request is expressed in the form of a URL and username and password if required.
The JDBC Driver
When driver is loaded into a JVM, it registers itself with the JDBC DriverManager. When a java application requests for a database connection, the DriverManager asks each Driver whether it can connect to the database specified in the given URL with provide username and password if required. As soon as it finds an appropriate Driver, the driver attempts to make a connection to the database. If the driver fails to get the connection, the Driver will throw a SQLException to the java application. If the driver gets the connection successfully, the Driver creates a Connection object and returns it to the java application.
The javax.sql.DataSource introduce in JDBC 2.0 , which is another method for establishing database connections. The DataSource is a named collection of connection properties that can be used to load a Driver and create a Connection
The JDBC Compliant Database
The lower bottom layer of the JDBC model is the database


You need a JDBC driver to connect to a database. There are four types of JDBC drivers.

Type 1 JDBC Driver(JDBC-ODBC Bridge):

The Type 1 driver translates all JDBC calls into ODBC calls and sends them to the ODBC driver. ODBC is a generic API. The JDBC-ODBC Bridge driver is recommended only for experimental use or when no other alternative is available.This driver is readily available as it comes with java version.Need to configure only.It is described in the end of this post.

Type 2 JDBC Driver(Native API driver):

The distinctive characteristic of type 2 jdbc drivers are that Type 2 drivers convert JDBC calls into database-specific calls i.e. this driver is specific to a particular database. Some distinctive characteristic of type 2 jdbc drivers are shown below. Example: Oracle will have oracle native api.Requires installation/configuration on client machines.

Type 3 JDBC Driver(All Java/Net-protocol driver):

Type 3 database requests are passed through the network to the middle-tier server. The middle-tier then translates the request to the database. If the middle-tier server can in turn use Type1, Type 2 or Type 4 drivers.

Type 4 JDBC Driver(Native-protocol/all-Java driver):


The Type 4 uses java networking libraries to communicate directly with the database server.The major benefit of using a type 4 jdbc drivers are that they are completely written in Java to achieve platform independence and eliminate deployment administration issues. It is most suitable for the web.We don’t need to do anything special to install a type 4 pure java driver. Download and put the driver JAR file in classpath.Thats it.








No comments:

Post a Comment