• +91 9723535972
  • info@interviewmaterial.com

JDBC Interview Questions and Answers

JDBC Interview Questions and Answers

Question - 51 : - How Can I Convert A Java Array To A Java.sql.array?

Answer - 51 : -

A Java array is a first class object and all of the references basically use PreparedStatement.setObject() or ResultSet.updateObject() methods for putting the array to an ARRAY in the database. Here's a basic example:

String[] as = { "One", "Two", "Three" };
PreparedStatement ps = con.prepareStatement( 
"UPDATE MYTABLE SET ArrayNums = ? WHERE MyKey = ?" );
ps.setObject( 1, as );

Question - 52 : - How Can I Insert Multiple Rows Into A Database In A Single Transaction?

Answer - 52 : -

//turn off the implicit commit 
//..your insert/update/delete goes here 
a new transaction is implicitly started. JDBC 2.0 provides a set of methods for executing a batch of database commands. Specifically, the java. sql. Statement interface provides three methods: addBatch(), clearBatch() and executeBatch(). Their documentation is pretty straight forward. The implementation of these methods is optional, so be sure that your driver supports these.

Question - 53 : - How Can I Connect To An Oracle Database Not On The Web Server From An Untrusted Applet?

Answer - 53 : -

You can use the thin ORACLE JDBC driver in an applet (with some extra parameters on the JDBC URL). Then, if you have NET8, you can use the connection manager of NET8 on the web server to proxy the connection request to the database server.

Question - 54 : - How Do I Get Runtime Information About The Jdbc Driver?

Answer - 54 : -

Use the following DatabaseMetaData methods:


Question - 55 : - How Can I Determine Whether A Statement And Its Resultset Will Be Closed On A Commit Or Rollback?

Answer - 55 : -

Use the DatabaseMetaData methods supportsOpen StatementsAcrossCommit() and supports Open Statements Across Rollback().

Question - 56 : - Is There A Practical Limit For The Number Of Sql Statements That Can Be Added To An Instance Of A Statement Object

Answer - 56 : -

While the specification makes no mention of any size limitation for Statement.addBatch(), this seems to be dependent, as usual, on the driver. Among other things, it depends on the type of container/collection used. I know of at least one driver that uses a Vector and grows as needed. I've seen questions about another driver that appears to peak somewhere between 500 and 1000 statements. Unfortunately, there doesn't appear to be any metadata information regarding possible limits. Of course, in a production quality driver, one would expect an exception from an addBatch() invocation that went beyond the command list's limits.

Question - 57 : - What Does Setfetchsize() Really Do?

Answer - 57 : -

The API documentation explains it pretty well, but a number of programmers seem to have a misconception of its functionality. The first thing to note is that it may do nothing at all; it is only a hint, even to a JDBC Compliant driver. setFetchSize() is really a request for a certain sized blocking factor, that is, how much data to send at a time.

Because trips to the server are expensive, sending a larger number of rows can be more efficient. It may be more efficient on the server side as well, depending on the particular SQL statement and the DB engine. That would be true if the data could be read straight off an index and the DB engine paid attention to the fetch size. In that case, the DB engine could return only enough data per request to match the fetch size. Don't count on that behavior. In general, the fetch size will be transparent to your program and only determines how often requests are sent to the server as you traverse the data. Also, both Statement and ResultSet have setFetchSize methods. If used with a Statement, all ResultSets returned by that Statement will have the same fetch size. The method can be used at any time to change the fetch size for a given ResultSet. To determine the current or default size, use the getFetchSize methods.

Question - 58 : - What Scalar Functions Can I Expect To Be Supported By Jdbc?

Answer - 58 : -

JDBC supports numeric, string, time, date, system, and conversion functions on scalar values. For a list of those supported and additional information, see section A.1.4 Support Scalar Functions in the JDBC Data Access API For Driver Writers. Note that drivers are only expected to support those scalar functions that are supported by the underlying DB engine.

Question - 59 : - What Does Normalization Mean For Java.sql.date And Java.sql.time?

Answer - 59 : -

These classes are thin wrappers extending java.util.Date, which has both date and time components. java.sql.Date should carry only date information and a normalized instance has the time information set to zeros. java.sql.Time should carry only time information and a normalized instance has the date set to the Java epoch ( January 1, 1970 ) and the milliseconds portion set to zero.

Question - 60 : - What Jdbc Objects Generate Sqlwarnings?

Answer - 60 : -

Connections, Statements and ResultSets all have a getWarnings method that allows retrieval. Keep in mind that prior ResultSet warnings are cleared on each new read and prior Statement warnings are cleared with each new execution. getWarnings() itself does not clear existing warnings, but each object has a clearWarnings method.

NCERT Solutions


Share your email for latest updates


Our partners