JDBC Architecture
JDBC Architecture
JDBC
----------
1.JDBC is a step by step process to intract with database from java applications inorder to perform
database operations from java applications.
2.JDBC is a technology, it will provide very good environment to connect with database from java
application inorder to perform database operations from java applications.
3.JDBC is a API[collection of classes and interfaces] it will provide environment to intract with database
from java applications inorder to perform database operations from java applications.
4.JDBC is an abstraction provided by SUN Microsystem and implemented by all database vendors
inorder to connect with database from java applications to perform database operations from java
application.
1
2
--abstract methods--
--impl by Oracle--
--impl by MySql--
--impl by DB2----
1.Type-1 Driver
2
3
2.Type-2 Driver
3.Type-3 Driver
4.Type-4 Driver
Tyape-1 Driver:
2.It was provided by SUN Microsystem as reference implementation for driver interface inorder to
provide environment for all the database vendors to implement drver interface.
3.SUN Microsystem has provided Type-1 driver in the form of sun.jdbc.odbc.JdbcOdbcDdriver in JAVA
4.This driver was provided by SUN Microsystem with the interdependency on the Microsoft product
“ODBC Driver” [open database connectivity].
5.ODBC is provided by Microsoft and implemented by using some native implementation and it will
provide very good environment to connect with any type of database from JDBC-ODBC Driver.
6.If we want to use Type-1 driver in JDBC applications thyen we must install ODBC Driver[ODBC native
library] in our system.
7.ODBC driver is available bydefault in Microsoft product but it is not available in Non Microsoft
product bydefault , so that, Type-1 driver is dependent on Microsoft products,Therefore, Type-1 drver s
less portable drver.
8.Type-1 driver is not suitable for web applications and distributed applications.
10.It is not for complex JDBC Applications it is for simple jdbc applications requirements.
3
4
11.Type-1 driver is slower driver,because,it must require two times conversions inorder to intract with
database from java applications.
1.From java to ODBC by JDBC-ODBC Driver
2.Type-2 Driver
---------------------
1.It is also called as “part java, part native driver” or simply “Native driver”.
2.Type-2 driver was prepared by using some java mplementation and by using Database vendor
provided native Liberary.
3.If we want to use Type-2 driver in JDBC applications then we have to install the respective DB vendor
provided native library in our machine.
4.when compared with type-1 driver, Type-2 driver is more portable driver.
5.when compared with type-1 driver, type-2 driver is faster driver, type-2 driver should not required two
times conversion, it is sufficient to have one time conversion to intract with database from java
applications.
6.when compared with type-1 driver, it will improve jdbc applications performance.
8.Type-2 driver is suggestible for standalone application only, not for web applications or enterprise
applications.
Type-3 Driver:
4
5
2.Type-1 driver and type-2 driver are suggestible for only standalone applications but, type-3 driver is
suggestible for web application and distributed applications.
3.Type-1 driver is dependent on ODBC Driver,Type-2 driver is dependent on Database vendor provided
Native Library, but Type-3 driver is dependent on Application server which we have used for our
applications.
4.Type-3 driver is more portable driver when compared with Type-1 and Type-2 Drivers.
5.Type-3 Driver is faster driver when compared with Type-1 and type-2 driver, because type-3 driver is
not required to perform two times conversion and it is not required to load DB vendor provided native
library,it is sufficient to start application server.
6.Type-3 driver will increase performance of the JDBC applications when compared type-1 and type-2
drivers.
7.Type-3 driver is able to provide very good environment to connect with multiple databases from
multiple client at a time.
8.it is not applicable for standalone applcatons,because, it must require server environment.
Type-4 Driver
5
6
5.It is possible to use type-4 driver with or with out application server.
7.Type-4 drver is light weight driver and faster driver when compared with type-1 and type-2,type-3
drivers.
------------------------------------------------------------------------------
Class c=Class.forName(“oracle.jdbc.OracleDriver”);
package java.sql;
6
7
--------
package oracle.jdbc;
static
DriverManager.registerDriver();
paclage java.sql;
-------
7
8
Class c=Class.forName("oracle.jdbc.OracleDriver");
Java.sql package
Driver[I]
DriverManager[C]
Connection[I]
Statement[I]
PreparedStatement[I]
CallableStatement[I]
ResultSet[I]
ResultSetMetaData[I]
DatabaseMetaData[I]
Driver URL:
Driver_URL:jdbc:oracle:thin:@localhost:1521:xe
DriverClass:com.mysql.jdbc.Driver
Driver_URL: jdbc:mysql://localhost:3306/db_Name
Q)In JDBC, Connection is an interface, but,how getConnection() method will create Connection object?
8
9
Ans:- JDBC is an abstraction[collection of interfaces] provided by SUN and implemented by all database
vendors.
package java.sql;
package com.oracle.jdbc;
package java.sql;
Driver.connect();
return con;
9
10
Statement st=con.createStatement();
Q)In JDBC, Statement is an interface then how it is possible to create Statement Object in
createStatement() method?
Ans-
package java.sql;
-------
-------
package com.oracle.jdbc;
10
11
return st;
Statement st=con.createStatement();
1.executeQuery(----)
2.executeUpdate(---)
3.execute(---)
11
12
select*from emp1;
12