Saturday, 1 September 2012

What does the JDBC Driver interface do?


• The JDBC Driver interface provides vendor-specific customized implementations of the abstract classes. 

• It is provided normally by the JDBC API. 

• For each vendor the driver provides implementations of the java.sql.Connection,
, PreparedStatement, Driver,Statement, ResultSet and CallableStatement.

How a database driver can be loaded with JDBC 4.0 / Java 6?


• By providing the JAR file , the driver must be properly configured.

• The JAR file is placed in the classpath. 

• It is not necessary to explicitly load the JDBC drivers by using the code like Class.forName() to register in the JDBC driver.

• The DriverManager class looks after this, via locating a suitable driver at the time when the DriverManager.getConnection() method is called. 

• This feature provides backward-compatibility, so no change is needed in the existing JDBC code.

Describe how the JDBC application works


A JDBC application may be divided into two layers:

• Driver layer

• Application layer

• The Driver layer consists of DriverManager class & the JDBC drivers.

• The Application layer begins after putting a request to the DriverManager for the connection.

• An appropriate driver is chosen and used for establishing the connection. 

• This connection is linked to the application layer.

• The application needs the connection for creating the Statement kind of objects by which the results are obtained.

Explain the life cycle of JDBC


The life cycle for a servlet comprises of the following phases:



• DriverManager : for managing a list of database drivers. 

• Driver : for communicating with the database. 

• Connection : for interfacing with all the methods for connecting a database.

• Statement : for encapsulating an SQL statement for passing to the database which had been parsed, compiled, planned and executed.

• ResultSet: for representing a set of rows retrieved for the query execution.


See Example Here:

http://java91.blogspot.in/2015/01/mysql-and-java-jdbc-connection-to.html

Briefly tell about the JDBC Architecture


The JDBC Architecture consists of two layers:

1.The JDBC API
2.The JDBC Driver API

• The JDBC API provides the application-JDBC Manager connection.

• The JDBC Driver API supports the JDBC Manager-to-Driver Connection.

• The JDBC API interacts with a driver manager, database-specific driver for providing transparent connectivity for the heterogeneous databases. 

• The JDBC driver manager authenticates that the correct driver has been used to access each data source.

• The driver manager supports multiple concurrent drivers connected to the multiple heterogeneous databases.

How do Java applications access the database using JDBC?


Java applications access the database using JDBC by : 

• Communicating with the database for Loading the RDBMS specific JDBC driver 

• Opening the connection with database 

• Sending the SQL statements and get the results back.

• Creating JDBC Statement object which contains SQL query.

• Executing statement to return the resultset(s) containing the tuples of database table which is a result of SQL query.

• Processing the result set.

• Closing the connection.

Name the new features added in JDBC 4.0.


The major features introduced in JDBC 4.0 are :

• Auto-loading by JDBC driver class. 

• Enhanced Connection management 

• RowId SQL enabled. 

• DataSet implemented by SQL by using Annotations

• Enhancements of SQL exception handling 

• Supporting SQL XML files.