Logo F2FInterview

JDBC Interview Questions

Q   |   QA

Common tasks of JDBC are as follows:

  1. Create an instance of a JDBC driver or load JDBC drivers through jdbc.drivers
  2. Register a driver
  3. Specify a database
  4. Open a database connection
  5. Submit a query
  6. Receive result
  7. Process result

List of interfaces used by JDBC with description are as follows:

Interface used to establish a connection to a database. SQL statements run within the context of a connection.
Interface used to return information about the database.
Interface used to locate the driver for a particular database management system.
Interface used to send precompiled SQL statements to the database server and obtain results.
Interface used to process the results returned from executing an SQL statement.
Interface used to return information about the columns in a ResultSet object.
Interface used to send static SQL statements to the database server and obtain results.
Receives events that a PooledConnection object generates.
Factory for PooledConnection objects. A ConnectionPoolDataSource object is usually registered with a JNDI service.
A factory for Connection objects. A DataSource object is usually registered with a JNDI service provider.
A PooledConnection object represents a physical connection to a data source.

Use of the JDBC-ODBC bridge from an untrusted applet running in a browser, such as Netscape Navigator, isn't allowed. The JDBC-ODBC bridge doesn't allow untrusted code to call it for security reasons. This is good because it means that an untrusted applet that is downloaded by the browser can't circumvent Java security by calling ODBC. Remember that ODBC is native code, so once ODBC is called the Java programming language can't guarantee that a security violation won't occur. On the other hand, Pure Java JDBC drivers work well with applets. They are fully downloadable and do not require any client-side configuration.
Finally, we would like to note that it is possible to use the JDBC-ODBC bridge with applets that will be run in appletviewer since appletviewer assumes that applets are trusted. In general, it is dangerous to turn applet security off, but it may be appropriate in certain controlled situations, such as for applets that will only be used in a secure intranet environment. Remember to exercise caution if you choose this option, and use an all-Java JDBC driver whenever possible to avoid security problems. 

A good way to find out what JDBC calls are doing is to enable JDBC tracing. The JDBC trace contains a detailed listing of the activity occurring in the system that is related to JDBC operations.

If you use the DriverManager facility to establish your database connection, you use the DriverManager.setLogWriter method to enable tracing of JDBC operations. If you use a DataSource object to get a connection, you use the DataSource.setLogWriter method to enable tracing. (For pooled connections, you use the ConnectionPoolDataSource.setLogWriter method, and for connections that can participate in distributed transactions, you use the XADataSource.setLogWriter method.) 

a. create a scrollable ResultSet object.

Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet srs = stmt.executeQuery("SELECT COLUMN_1,

b. use a built in methods like afterLast(), previous(), beforeFirst(), etc. to scroll the resultset.

while (srs.previous()) {
String name = srs.getString("COLUMN_1");
float salary = srs.getFloat("COLUMN_2");

c. to find a specific row, use absolute(), relative() methods.

srs.absolute(4); // cursor is on the fourth row
int rowNum = srs.getRow(); // rowNum should be 4
int rowNum = srs.getRow(); // rowNum should be 1
int rowNum = srs.getRow(); // rowNum should be 3

d. use isFirst(), isLast(), isBeforeFirst(), isAfterLast() methods to check boundary status. 

In order to link this F2FInterview's page as Reference on your website or Blog, click on below text area and pres (CTRL-C) to copy the code in clipboard or right click then copy the following lines after that paste into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code: