Saturday, November 17, 2012

Java Database Connectivity(JDBC) drivers and Steps of Connectivity


JDBC Drivers
-JDBC ODBC Bridge Driver
-Native API Driver
-Network Protocol Driver
-Thin Driver

1-JDBC ODBC Bridge Driver
Type 1 Driver uses ODBC Driver to Connect to the Database.This Driver converts JDBC methods calls into ODBC function calls.
-low performance
-ODBC driver needs to be install on every client machine.

2-Native API Driver
Type 2 Driver uses client side Libraries of Database.The driver converts JDBC method calls into Native calls of the Database API's.
-Performance more than Type 1
-Need to be Install on every client machine.

3-Network Protocol Driver
Completely written in Java.
Type 3 driver uses application server that converts JDBC calls Directly or Indirectly into vender specific Database Protocol.
-Not need to install on each machine
-more costly

4-Thin Driver
Type 4 driver converts JDBC calls directly into vender specific Database Protocol.
-Best Driver Currently in use

Steps to use JDBC
Step 1: Register the Driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Step 2: Create Connection
Connection con=DriverManager.getConnection("jdbc:odbc:dsnname");

Step 3: Create Statement
Statement st=con.createStatement();

Step 4: Execute Query
ResultSet rs=st.executeQuery("select * from table_name");

Step 5: Get Result Set
While(rs.next())
{System.out.println(rs.getString(Column_no));
}

Step 6: Close the Connection
con.close();

No comments:

Popular Posts