Home Interview Questions and Answers JDBC Interview Questions and Answers For Freshers Part-3

jdbc21.What do you mean by fastest type of JDBC driver?
JDBC driver performance or fastness depends on a number of issues Quality of the driver code, size of the driver code, database server and its load, Network topology, Number of times your request is translated to a different API.

22.In real time project which driver did you use?
Tell about your real time experience.

23.How do you create a connection object?
There are 3 overloaded DriverManager.getConnection() methods to create a connection object

getConnection(String url, String user, String password)Using a database URL with a username and password. For example

String URL = “jdbcoraclethin@amrood1521EMP”;
String USER = “username”;
String PASS = “password”
Connection conn = DriverManager.getConnection(URL, USER, PASS);
getConnection(String url)Using only a database URL. For example
String URL = “jdbcoraclethinusername/password@amrood1521EMP”;
Connection conn = DriverManager.getConnection(URL);
getConnection(String url, Properties prop)Using a database URL and a Properties object. For example
String URL = “jdbcoraclethin@amrood1521EMP”;
Properties info = new Properties( );
info.put( “user”, “username” );
info.put( “password”, “password” );

24.How can I determine whether a Statement and its ResultSet will be closed on a commit or rollback?
Use the DatabaseMetaData methods supportsOpenStatementsAcrossCommit() and supportsOpenStatementsAcrossRollback() to check.

25.Is there a practical limit for the number of SQL statements that can be added to an instance of a Statement object?
The specification makes no mention of any size limitation for Statement.addBatch(), this is dependent, on the driver.

26.How cursor works in scrollable result set?
There are several methods in the ResultSet interface that involve moving the cursor, like beforeFirst(), afterLast(), first(), last(), absolute(int row), relative(int row), previous(), next(), getRow(), moveToInsertRow(), moveToCurrentRow().

27.How can you view a result set?
ResultSet interface contains get methods for each of the possible data types, and each get method has two versions

One that takes in a column name.

One that takes in a column index.

For e.g. getInt(String columnName), getInt(int columnIndex)

28.How do you update a result set?
ResultSet interface contains a collection of update methods for updating the data of a result set. Each update method has two versions for each data type

One that takes in a column name.

One that takes in a column index.

These methods change the columns of the current row in the ResultSet object, but not in the underlying database. To update your changes to the row in the database, you need to invoke one of the following methods

updateRow(), deleteRow(), refreshRow(), cancelRowUpdates(), insertRow()

29.How does JDBC handle the data types of Java and database?
The JDBC driver converts the Java data type to the appropriate JDBC type before sending it to the database. It uses a default mapping for most data types. For example, a Java int is converted to an SQL INTEGER.

30.What causes “No suitable driver” error?
“No suitable driver” is occurs during a call to the DriverManager.getConnection method, may be of any of the following reason

Due to failing to load the appropriate JDBC drivers before calling the getConnection method.

It can be specifying an invalid JDBC URL, one that is not recognized by JDBC driver.

This error can occur if one or more the shared libraries needed by the bridge cannot be loaded.

You may also like

Leave a Comment