Skip to Content

TheBlogReaders.com

Salesforce.com, PHP, MySQL, Javascript, Ajax, Htacces

JDBC Interview Questions and Answers For Freshers Part-2

Be First!

jdbc11.What are JDBC driver types?
There are four types of JDBC drivers

JDBC-ODBC Bridge plus ODBC driver − also called Type 1 calls native code of the locally available ODBC driver.

Native-API, partly Java driver − also called Type 2 calls database vendor native library on a client side. This code then talks to database over network.

JDBC-Net, pure Java driver − also called Type 3 the pure-java driver that talks with the server-side middleware that then talks to database.

Native-protocol, pure Java driver − also called Type 4 the pure-java driver that uses database native protocol.

12.When should each of the JDBC driver type be used?
Following is a list as to when the four types of drivers can be used

If you are accessing one type of database, such as Oracle, Sybase, or IBM, the preferred driver type is 4.

If your Java application is accessing multiple types of databases at the same time, type 3 is the preferred driver.

Type 2 drivers are useful in situations where a type 3 or type 4 driver is not available yet for your database.

The type 1 driver is not considered a deployment-level driver and is typically used for development and testing purposes only.

13.Which type of JDBC driver is the fastest one?
JDBC Net pure Java driver(Type 4) is the fastest driver because it converts the JDBC calls into vendor specific protocol calls and it directly interacts with the database.

14.Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection?
No. You can open only one Statement object per connection when you are using the JDBC-ODBC Bridge.

15.What are the standard isolation levels defined by JDBC?
The standard isolation levels are

TRANSACTION_NONE

TRANSACTION_READ_COMMITTED

TRANSACTION_READ_UNCOMMITTED

TRANSACTION_REPEATABLE_READ

TRANSACTION_SERIALIZABLE

16.What is the design pattern followed by JDBC?
JDBC architecture decouples an abstraction from its implementation. Hence JDBC follows a bridge design pattern. The JDBC API provides the abstraction and the JDBC drivers provide the implementation. New drivers can be plugged-in to the JDBC API without changing the client code.

17.What are the different types of JDBC Statements?
Types of statements are

Statement − regular SQL statement.

PreparedStatement − more efficient than statement due to pre-compilation of SQL.

CallableStatement − to call stored procedures on the database.

18.What is difference between statement and prepared statement?
Prepared statements offer better performance, as they are pre-compiled. Prepared statements reuse the same execution plan for different arguments rather than creating a new execution plan every time. Prepared statements use bind arguments, which are sent to the database engine. This allows mapping different requests with same prepared statement but different arguments to execute the same execution plan. Prepared statements are more secure because they use bind variables, which can prevent SQL injection attack.

19.How do you register a driver?

There are 2 approaches for registering the Driver
Class.forName() − This method dynamically loads the driver’s class file into memory, which automatically registers it. This method is preferable because it allows you to make the driver registration configurable and portable.

DriverManager.registerDriver() − This static method is used in case you are using a non-JDK compliant JVM, such as the one provided by Microsoft.

20.What are the benefits of JDBC 4.0?
Here are few advantages of JDBC 4.0

Auto loading of JDBC driver class. In the earlier versions we had to manually register and load drivers using class.forName.

Connection management enhancements. New methods added to javax.sql.PooledConnection.

DataSet Implementation of SQL using annotations.

SQL XML support.

(154)

Previous
Next

Leave a Reply