JDBC is an API specification developed by Sun Microsystems
that defines a uniform interface for accessing various relational
databases. JDBC is a core part of the Java platform and is included in
the standard JDK distribution.
The primary function of the JDBC API is to provide a means for the developer to issue SQL statements and process the results in a consistent, database-independent manner. JDBC provides rich, object-oriented access to databases by defining classes and interfaces that represent objects such as:
Layers of the JDBC Architecture
A JDBC driver translates standard JDBC calls into a network or database protocol or into a database library API call that facilitates communication with the database. This translation layer provides JDBC applications with database independence. If the back-end database changes, only the JDBC driver need be replaced with few code modifications required. There are four distinct types of JDBC drivers.
Type 1 JDBC-ODBC Bridge. Type 1 drivers act as a "bridge" between JDBC and another database connectivity mechanism such as ODBC. The JDBC- ODBC bridge provides JDBC access using most standard ODBC drivers. This driver is included in the Java 2 SDK within the sun.jdbc.odbc package. In this driver the java statements are converted to a jdbc statements. JDBC statements calls the ODBC by using the JDBC-ODBC Bridge. And finally the query is executed by the database. This driver has serious limitation for many applications. (See Figure 2.)
Type 1 JDBC Architecture
Type 2 Java to Native API. Type 2 drivers use the Java Native Interface (JNI) to make calls to a local database library API. This driver converts the JDBC calls into a database specific call for databases such as SQL, ORACLE etc. This driver communicates directly with the database server. It requires some native code to connect to the database. Type 2 drivers are usually faster than Type 1 drivers. Like Type 1 drivers, Type 2 drivers require native database client libraries to be installed and configured on the client machine. (See Figure 3.)
Type 2 JDBC Architecture
Type 3 Java to Network Protocol Or All- Java Driver. Type 3 drivers are pure Java drivers that use a proprietary network protocol to communicate with JDBC middleware on the server. The middleware then translates the network protocol to database-specific function calls. Type 3 drivers are the most flexible JDBC solution because they do not require native database libraries on the client and can connect to many different databases on the back end. Type 3 drivers can be deployed over the Internet without client installation. (See Figure 4.)
Java-------> JDBC statements------> SQL statements ------> databases.
Type 3 JDBC Architecture
Type 4 Java to Database Protocol. Type 4 drivers are pure Java drivers that implement a proprietary database protocol (like Oracle's SQL*Net) to communicate directly with the database. Like Type 3 drivers, they do not require native database libraries and can be deployed over the Internet without client installation. One drawback to Type 4 drivers is that they are database specific. Unlike Type 3 drivers, if your back-end database changes, you may save to purchase and deploy a new Type 4 driver (some Type 4 drivers are available free of charge from the database manufacturer). However, because Type drivers communicate directly with the database engine rather than through middleware or a native library, they are usually the fastest JDBC drivers available. This driver directly converts the java statements to SQL statements.
(See Figure 5.)
Type 4 JDBC Architecture
So, you may be asking yourself, "Which is the right type of driver for your application?" Well, that depends on the requirements of your particular project. If you do not have the opportunity or inclination to install and configure software on each client, you can rule out Type 1 and Type 2 drivers.
However, if the cost of Type 3 or Type 4 drivers is prohibitive, Type 1 and type 2 drivers may become more attractive because they are usually available free of charge. Price aside, the debate will often boil down to whether to use Type 3 or Type 4 driver for a particular application. In this case, you may need to weigh the benefits of flexibility and interoperability against performance. Type 3 drivers offer your application the ability to transparently access different types of databases, while Type 4 drivers usually exhibit better performance and, like Type 1 and Type 2 drivers, may be available free if charge from the database manufacturer.
The primary function of the JDBC API is to provide a means for the developer to issue SQL statements and process the results in a consistent, database-independent manner. JDBC provides rich, object-oriented access to databases by defining classes and interfaces that represent objects such as:
- Database connections
- SQL statements
- Result Set
- Database metadata
- Prepared statements
- Binary Large Objects (BLOBs)
- Character Large Objects (CLOBs)
- Callable statements
- Database drivers
- Driver manager
Layers of the JDBC Architecture
A JDBC driver translates standard JDBC calls into a network or database protocol or into a database library API call that facilitates communication with the database. This translation layer provides JDBC applications with database independence. If the back-end database changes, only the JDBC driver need be replaced with few code modifications required. There are four distinct types of JDBC drivers.
Type 1 JDBC-ODBC Bridge. Type 1 drivers act as a "bridge" between JDBC and another database connectivity mechanism such as ODBC. The JDBC- ODBC bridge provides JDBC access using most standard ODBC drivers. This driver is included in the Java 2 SDK within the sun.jdbc.odbc package. In this driver the java statements are converted to a jdbc statements. JDBC statements calls the ODBC by using the JDBC-ODBC Bridge. And finally the query is executed by the database. This driver has serious limitation for many applications. (See Figure 2.)
Type 1 JDBC Architecture
Type 2 Java to Native API. Type 2 drivers use the Java Native Interface (JNI) to make calls to a local database library API. This driver converts the JDBC calls into a database specific call for databases such as SQL, ORACLE etc. This driver communicates directly with the database server. It requires some native code to connect to the database. Type 2 drivers are usually faster than Type 1 drivers. Like Type 1 drivers, Type 2 drivers require native database client libraries to be installed and configured on the client machine. (See Figure 3.)
Type 2 JDBC Architecture
Type 3 Java to Network Protocol Or All- Java Driver. Type 3 drivers are pure Java drivers that use a proprietary network protocol to communicate with JDBC middleware on the server. The middleware then translates the network protocol to database-specific function calls. Type 3 drivers are the most flexible JDBC solution because they do not require native database libraries on the client and can connect to many different databases on the back end. Type 3 drivers can be deployed over the Internet without client installation. (See Figure 4.)
Java-------> JDBC statements------> SQL statements ------> databases.
Type 3 JDBC Architecture
Type 4 Java to Database Protocol. Type 4 drivers are pure Java drivers that implement a proprietary database protocol (like Oracle's SQL*Net) to communicate directly with the database. Like Type 3 drivers, they do not require native database libraries and can be deployed over the Internet without client installation. One drawback to Type 4 drivers is that they are database specific. Unlike Type 3 drivers, if your back-end database changes, you may save to purchase and deploy a new Type 4 driver (some Type 4 drivers are available free of charge from the database manufacturer). However, because Type drivers communicate directly with the database engine rather than through middleware or a native library, they are usually the fastest JDBC drivers available. This driver directly converts the java statements to SQL statements.
(See Figure 5.)
Type 4 JDBC Architecture
So, you may be asking yourself, "Which is the right type of driver for your application?" Well, that depends on the requirements of your particular project. If you do not have the opportunity or inclination to install and configure software on each client, you can rule out Type 1 and Type 2 drivers.
However, if the cost of Type 3 or Type 4 drivers is prohibitive, Type 1 and type 2 drivers may become more attractive because they are usually available free of charge. Price aside, the debate will often boil down to whether to use Type 3 or Type 4 driver for a particular application. In this case, you may need to weigh the benefits of flexibility and interoperability against performance. Type 3 drivers offer your application the ability to transparently access different types of databases, while Type 4 drivers usually exhibit better performance and, like Type 1 and Type 2 drivers, may be available free if charge from the database manufacturer.
The JDBC 1.0 API was the first
officially JDBC API launched consists of the following java classes and
interfaces that you can open connections to particular databases.
1). The JDBC 1.0 API.
2). The JDBC 1.2 API.
3). The JDBC 2.0 Optional
Package API.
4). The JDBC 2.1 core
API.
5) The JDBC 3.0 API.
6) The JDBC 4.0 API.
Features of JDBC 1.0 API
The JDBC 1.0 API was the
first officially JDBC API launched consists of the following java classes and
interfaces that you can open connections to particular databases.
This version includes a
completely redesigned administration console with an enhanced graphical
interface to manage and monitor distributed virtual databases.
Features of JDBC 1.2 API
1). It supports
Updatabale ResultSets.
2). The DatabaseMetaData
code has been refactored to provide more transparency with regard to the
underlying database engine.
3) New pass through
schedulers for increased performance.
Features of The JDBC 2.0 Optional Pacakage API
1). The use of DataSource
interface for making a connection.
2). Use of JNDI to
specify and obtain database connections.
3). It allows us to use
Pooled connections, that is we can reuse the connections.
4). In this version the
distrbuted transactions is possible.
5). It provides a way of
handling and passing data using Rowset technology.
Features of the JDBC 2.1
core API.
1). Scroll forward and
backward in a result set or has the ability to move to a specific row.
2). Instead of using SQL
commands, we can make updates to a database tables using methods in the Java
programming language
3). We can use multiple
SQL statements in a a database as a unit, or batch.
4). It uses the SQL3
datatypes as column values. SQL3 types are Blob, Clob, Array, Structured type,
Ref.
5). Increased support for
storing persistent objects in the java programming language.
6). Supports for time
zones in Date, Time, and Timestamp values.
7). Full precision for
java.math.BigDecimal values.
Features of JDBC 3.0 API
1). Reusabilty of
prepared statements by connection pools.
2). In this version there
is number of properties defined for the ConnectionPoolDataSource. These
properties can be used to describe how the PooledConnection objects created by
DataSource objects should be pooled.
3) A new concept has been
added to this API is of savepoints.
4). Retrieval of
parameter metadata.
5). It has added a means
of retrieving values from columns containing automatically generated values.
6). Added a new data type
i.e. java.sql.BOOLEAN.
7). Passing parameters to
CallableStatement.
8). The data in the Blob
and Clob can be altered.
9). DatabaseMetaData API
has been added.
Features of JDBC 4.0 :
1). Auto- loading of JDBC
driver class.
2). Connection management
enhancements.
3.) Support for RowId SAL
type.
4). SQL exception
handling enhancements.
5). DataSet
implementation of SQl using Annotations.
6). SQL XML support
Reusabilty of prepared statements by
connection pools. In this version there is number of properties defined for the
ConnectionPoolDataSource.
Features
of JDBC 3.0 API
1.
Reusabilty
of prepared statements by connection pools.
2.
In this version there is
number of properties defined for the ConnectionPoolDataSource. These
properties can be used to describe how the PooledConnection objects
created by DataSource objects should be pooled.
3.
A new concept has been
added to this API is of savepoints: One of the useful new features is
transactional savepoints. With JDBC 3.0, the transactional model is now more
flexible. Now you can start a transaction , insert several rows in it and then
create a savepoint. This savepoint serves as a bookmark. The application can
rollback to the savepoint and then commit the group of inserts as if the
updates have never been attempted. For eg:
Statement st=connection.createStatement();
int rowcount=st.executeUpdate("insert into employee values("tim"));
int rowcoutn=st.executeUpdate("insert into salary values(20000.0);
Savepoint sv=connection.setSavePoint("savepoint"); //create save point for inserts
int rowcount=st.executeUpdate("delete from employee");
connection.rollback(sv); //discard the delete statement but keeps the inserts
connection.commit(); //inserts are now permanent
Statement st=connection.createStatement();
int rowcount=st.executeUpdate("insert into employee values("tim"));
int rowcoutn=st.executeUpdate("insert into salary values(20000.0);
Savepoint sv=connection.setSavePoint("savepoint"); //create save point for inserts
int rowcount=st.executeUpdate("delete from employee");
connection.rollback(sv); //discard the delete statement but keeps the inserts
connection.commit(); //inserts are now permanent
4.
Retrieval of parameter metadata.
5.
It has added a means of
retrieving values from columns containing automatically generated
values.
6.
Added a new data type
i.e. java.sql.BOOLEAN.
7.
Passing parameters to CallableStatement.
8.
The data in the Blob
and Clob can be altered: JDBC 3.0 introduces a standard mechanism
for updating BLOB and CLOB data.
9.
DatabaseMetaData API has been added.
10.
It allows stored procedure
parameters to be called by name.
JDBC 4 is a major new release with a
strong focus ease-of-use and programmer productivity. JDBC 4's key priority is
to make it easier for developers to work directly with the JDBC API.
Features
of JDBC 4.0
JDBC 4 is a major new
release with a strong focus ease-of-use and programmer
productivity. JDBC 4's key priority is to make it easier for developers
to work directly with the JDBC API. The new features availble in J2SE 1.5 added
ease-of-development features in JDBC 4
In addition to
ease-of-use, JDBC 4 introduces several SQL 203 features, like Java specific
mapping for the new XML SQL type. Now in JDBC 4 every PreparedStatement is
poolable by default.
1.
Auto-
loading of JDBC driver class: In JDBC 4 invoking the getConnection() on DriverManager
will automatically load a driver. Upon loading the driver, an instance of the
driver is created and the registerDriver() method is invoked to make
that driver available to clients.
2.
Connection
management enhancements: In
jdbc it may happen that a Connection is lying idle or not closed in a pool,
then it became stale over time. This will led to the connection pool run out of
resources due to stale connection. We know that the stale connection doesn't
mean that a connection is closed. Now in JDBC 4 Connection class we have
provided one method isValid(), which allows a client to query the
database driver if a connection is still valid. As database is a shared
resource, so many application can access the same data store. To maintain all
the records of the client is a difficult task, now in JDBC 4 an application can
associate metadata with a database connection via the setClientInfo() method,
which takes a name/value pair, or a Properties object.
3.
Support
for RowId data type: JDBC introduces
support for ROWID, a data type that had been in use in database products even
before it became part of the SQL.
4.
SQL
exception handling enhancements: JDBC 4 addresses the error handling beautifully. As databases are
often remotely accessible resources, problems such as network failures is
common and it can cause exceptions when executing a database operation.
SQL statements can also cause exceptions. Prior to JDBC 4, most JDBC operations
generated a simple SQLException.
5.
SQL
XML support:
6.
DataSet
implementation of SQL using Annotations: The JDBC 4.0 specification leverages annotations to allow
developers to associate a SQL query with a Java class without a need to write a
lot of code to achieve this association.
కామెంట్లు లేవు:
కామెంట్ను పోస్ట్ చేయండి