Top 50+ JDBC Interview Questions and Answers - 3

Question: 11

How do you load a driver?

Using Driver class.forName(java.lang.String driverclass) or registerDriver(Driver driver).

Question: 12

How do you implement connection pooling?

Connection Pooling can be implemented by the following way.

A javax.sql.ConnectionPoolDataSource interface that serves as a resource manager connection factory for pooled java.sql.Connection objects.

Each database vendors provide the implementation for that instance.

For example, the oracle vendors implementation as follows

oracle.jdbc.pool.oracleConnectionPoolDataSource Class.

A javax.sql.PooledConnection interface encapsulates the physical connection for the database. Again the vendor provides the implementation.

Question: 13

What does setAutoCommit do?

setAutoCommit() invoke the commit state query to the database.

To perform batch updation we use the setAutoCommit() which enables us to execute more than one statement together, which in result minimize the database call and send all statements in one batch.

setAutoCommit() allowed us to commit the transaction commit state manually the default values of the SetAutoCommit() is true.

Question: 14

What is the use of getGeneratedKeys() method in Statement?

Sometimes a table can have auto generated keys used to insert the unique column value for primary key.

We can use Statement getGeneratedKeys() method to get the value of this auto generated key.

Question: 15

What is stored procedure?

Stored procedure is a group of SQL statements that forms a logical unit and performs a particular task.

Stored procedures are used to encapsulate a set of operations or queries to execute on database.

Stored procedure can be compiled and executed with different parameters and results and may have any combination of input/output parameters.

Related Questions