Saturday, 25 May 2013


1.What is the JDBC?
Java Database Connectivity (JDBC) is a standard Java API to interact with relational databases form Java. JDBC has set of classes and interfaces which can use from Java application and talk to database without learning RDBMS details and using Database Specific JDBC Drivers.

2.What are the new features added to JDBC 4.0?
The major features added in JDBC 4.0 include :
  • Auto-loading of JDBC driver class
  • Connection management enhancements
  • Support for RowId SQL type
  • DataSet implementation of SQL using Annotations
  • SQL exception handling enhancements
  • SQL XML support

3.Explain Basic Steps in writing a Java program using JDBC?
JDBC makes the interaction with RDBMS simple and intuitive. When a Java application needs to access database :
  • Load the RDBMS specific JDBC driver because this driver actually communicates with the database (Incase of JDBC 4.0 this is automatically loaded).
  • Open the connection to database which is then used to send SQL statements and get results back.
  • Create JDBC Statement object. This object contains SQL query.
  • Execute statement which returns resultset(s). ResultSet contains the tuples of database table as a result of SQL query.
  • Process the result set.
  • Close the connection.
5.What are the main components of JDBC ?
The life cycle of a servlet consists of the following phases:

  1. DriverManager: Manages a list of database drivers. Matches connection requests from the java application with the proper database driver using communication subprotocol. The first driver that recognizes a certain subprotocol under JDBC will be used to establish a database Connection.
  2. Driver: The database communications link, handling all communication with the database. Normally, once the driver is loaded, the developer need not call it explicitly.
  3. Connection : Interface with all methods for contacting a database.The connection object represents communication context, i.e., all communication with database is through connection object only.
  4. Statement : Encapsulates an SQL statement which is passed to the database to be parsed, compiled, planned and executed.
  5. ResultSet: The ResultSet represents set of rows retrieved due to query execution.

6.How the JDBC application works?
A JDBC application can be logically divided into two layers:
1. Driver layer
2. Application layer
  • Driver layer consists of DriverManager class and the available JDBC drivers.
  • The application begins with requesting the DriverManager for the connection.
  • An appropriate driver is choosen and is used for establishing the connection. This connection is given to the application which falls under the application layer.
  • The application uses this connection to create Statement kind of objects, through which SQL commands are sent to backend and obtain the results.

JDBC Application

Figure 2: JDBC Application