Saturday 25 May 2013

JAVA INTERVIEW QUESTIONS - JDBC



7.How do I load a database driver with JDBC 4.0 / Java 6?
Provided the JAR file containing the driver is properly configured, just place the JAR file in the classpath. Java developers NO longer need to explicitly load JDBC drivers using code like Class.forName() to register a JDBC driver.The DriverManager class takes care of this by automatically locating a suitable driver when theDriverManager.getConnection() method is called. This feature is backward-compatible, so no changes are needed to the existing JDBC code.

8.What is JDBC Driver interface?
The JDBC Driver interface provides vendor-specific implementations of the abstract classes provided by the JDBC API. Each vendor driver must provide implementations of thejava.sql.Connection,Statement,PreparedStatement, CallableStatement, ResultSet and Driver.

9.What does the connection object represents?
The connection object represents communication context, i.e., all communication with database is through connection object only.

10.What is Statement ?
Statement acts like a vehicle through which SQL commands can be sent. Through the connection object we create statement kind of objects.
Through the connection object we create statement kind of objects.

               Statement stmt  = conn.createStatement();

This method returns object which implements statement interface.

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

17.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.

18.Which is the right type of driver to use and when?

  • Type I driver is handy for prototyping
  • Type III driver adds security, caching, and connection control
  • Type III and Type IV drivers need no pre-installation


19.What are the standard isolation levels defined by JDBC?
The values are defined in the class java.sql.Connection and are:

  • TRANSACTION_NONE
  • TRANSACTION_READ_COMMITTED
  • TRANSACTION_READ_UNCOMMITTED
  • TRANSACTION_REPEATABLE_READ
  • TRANSACTION_SERIALIZABLE

Any given database may not support all of these levels.

20.What is resultset ?
The ResultSet represents set of rows retrieved due to query execution.
  ResultSet rs = stmt.executeQuery(sqlQuery);


EmoticonEmoticon