Tuesday, May 1, 2007

DATABASE connectivity in JAVA using JDBC Driver

Different Typs of Driver Available in JAVA

Type 1: JDBC-ODBC Bridge

The type 1 driver, JDBC-ODBC Bridge , translates all JDBC calls into ODBC (Open DataBase Connectivity) calls and sends them to the ODBC driver. As such, the ODBC driver, as well as, in many cases, the client database code, must be present on the client machine.

Java--->JDBCStat-->JDBC-ODBC bridge-->ODBC-->Databases

Type 2: Native-API/partly Java driver

JDBC driver type 2 -- the native-API/partly Java driver -- converts JDBC calls into database-specific calls for databases such as SQL Server, Informix, Oracle, or Sybase. The type 2 driver communicates directly with the database server; therefore it requires that some binary code be present on the client machine.

Type 3: Net-protocol/ all-Java driver

JDBC driver type 3 -- the net-protocol/ all-Java driver -- follows a three-tiered approach whereby the JDBC database requests are passed through the network to the middle-tier server. The middle-tier server then translates the request (directly or indirectly) to the database-specific native-connectivity interface to further the request to the database server. If the middle-tier server is written in Java, it can use a type 1 or type 2 JDBC driver to do this.

Java-->JDBC statements-->SQLStatements- -> databases.

Type 4 Pure Java Driver

Type 4 JDBC drivers are direct-to-database pure Java drivers ("thin" drivers). A Type 4 driver takes JDBC calls and translates them into the network protocol (proprietary protocol) used directly by the DBMS. Thus, client machines or application servers can make direct calls to the DBMS server. Each DBMS requires its own Type 4 driver; therefore, there are more drivers to manage in a heterogeneous computing environment, but this is outweighed by the fact that Type 4 drivers provide faster performance and direct access to DBMS features.

Examples J

// Class.forName("sun.jdbc.odbc. JdbcOdbcDriver");//for MS Access
//con = DriverManager. getConnection("jdbc:odbc:dataSourc eName");//for Ms Access TYPE1


//Class.forName("sun.jdbc.odbc. JdbcOdbcDriver");//for SQL Server
//con=DriverManager .getConnection("jdbc:odbc:dataSourc eName","username","password");//for sQL Server TYPE1


Class.forName("com.microsoft. jdbc.sqlserver. SQLServerDriver"); //usign SQL SERVER 2K JDBC Driver
con=DriverManager. getConnection("jdbc:microsoft: sqlserver: //localhost: 1433;databaseNam e=dataSourceName ;selectMethod= cursor;","username","password");
TYPE 2

//Class.forName("net.avenir.jdbc2. Driver"); //atinav 2.5 JDBC driver(www.atinav. com:-30 days trial version jdm)
//con=DriverManager .getConnection("jdbc:AvenirDriver: //localhost: 1433/dataSourceN ame","username","password");
TYPE 3

//Class.forName("com.jnetdirect. jsql.JSQLDriver"); //JSQLConnect JDBC driver(http://www.j- netdirect. com/DownloadSoft ware.html: -30 days trial version )
//con=DriverManager .getConnection("jdbc:JSQLConnect: //localhost/ dataSourceName","username","password");
TYPE 3

//Class.forName("com.mysql.jdbc. Driver");// for mySQL
//con = DriverManager. getConnection("jdbc:mysql:/ /localhost/ dataSourceName? user=username&password=password");// need to download MySQL Connector/J

TYPE 4 because mysql connector is a type 4 driver

1 comment:

vedha said...

It was very useful for developers and very nice examples

Global Tech Soft Solution

Smart software solution.

Webdesigning, software Development & Consultant GlobalTech Soft Solution