Top 50+ JDBC Interview Questions and Answers - 2

Question: 6

Why PreparedStatements are faser?

PreparedStatements execution is faster than direct execution for statements executed more than three or four times because the statements is compiled only once.

Prepared statements and JDBC driver are linked with each other.

We can bind drivers with columns by triggering the query into the database.

When we execute Connection prepareStatement(), all the columns bindings take place, in order to reduce the time.

Question: 7

Write the syntax of URL to get connection?

jdbc:<subprotocol>:<subname>

jdbc: is a protocol. This is only allowed protocol in JDBC.

<subprotocol>: The subprotocol is used to identify a database driver, or the name of the database connectivity mechanism, chosen by the database driver providers.

<subname>: The syntax of the subname is driver specific. The driver may chosen any syntax appropriate for its implementation.

Question: 8

Can java objects be stored in database?

Yes. We can store java objects. By using setObjects(), setBlob() and setClob() methods in PreparedStatement.

Question: 9

What causes No suitable driver error?

No suitable driver is occurs during a call to the DriverManager.getConnection method, may be any of the following reasons.

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.

Question: 10

How to set NULL values in JDBC PreparedStatement?

We can use PreparedStatement setNull() method to bind the null variable to a parameter.

The setNull method takes index and SQL Types as arguments, for example

ps.setNull(10, java.sql.Types.INTEGER);

Related Questions