Java Database Connectivity (JDBC) Interview Questions

Interview Questions in JDBC

1. What does the Statement interface enable you to do ?
It enables you to execute static SQL statements.

2. What does the executeQuery( ) method do?
It executes a SQL Select statement and returns a result set.

3. What is stored in a ResultSet object ?
The cursor for a SQL Select statement.

4. What three exceptions can be thrown in JDBC applications ?
SQLException, SQLWarning, and DataTruncation.

5. What method usually throw the SQLException exception ?
All JDBC methods.

6. What three types of parameters can you pass into a stored procedure?
IN,OUT, and INOUT parameters

7. How many types of JDBC Drivers are present and what are they?
There are 4 types of JDBC Drivers
JDBC—ODBC Bridge Driver
Native API Partly Java Driver _
Network protocol Driver r
JDBC Net pure Java Driver
The type 4 driver is called thin driver.

8. What method will get the properties needed to connect to the database ?
getPropertyInfo( )

9. What does a driver need to support in order to be JDBC-complaint ?

10. In what system property does the DriverManager object look for driver objects ?

11. List the three different methods that the DiriverManager can use to create a _ connection to the database.
getC0nnection( String ), getConnection(String, Properites ) and
getConnection( String, String, String)

12. What is the difference between a connection and a statement ?
connection is a link to a database; a statement is used to send commands
to a database.

13. Why would you use the execute( ) method of the Statement object ?
If the SQL statement returned multiple results.

14. Describe the effects of commit and rollback ?
Commit will clear the log and make changes permanent; rollback will
clear the log and reset the database to its original state.

15. Is a Statement object used for static or dynamic SQL statements ?
It is used for static statements only.

16. What is the difference between executeQuery( ) and executeUpdate( ) ? executeQuery( ) will execute a SQL Select statement and returns an object of Result. executeUpdate( ) will execute SQL Insert, Delete, and Update

statements and returns an integer number that represents the number of
records effected with the SQL command.

17. How do you create a ResultSetMetaData object ?
Use the getMetaData( ) method of ResultSet.

18. What are the different types of database tables ?
User tables and system tables.

19. What is the syntax for getting a list of columns for a table ?
getColumns( )

20. What is the difference between getExportedKeys() and getImportedKeys( )’?
Exported keys are primary keys in a table that are used in other tables,
whereas imported keys are columns used in a table that are part of the
primary key in another table.

21. What character do you use to indicate a dynamic parameter ?
The ? character.

22. What getColumnLabel( int ) of ResultSetMetaData returns ?
The label of the column passed as parameter.

23. What method is used to create a PreparedStatement object?
prepareStatement( String ) of Connection interface.

24. What method is used to create a CallableStatement object ?
prepareCall( String ) of Connection interface.

25. What does the wasNull( ) method tell you ?
Determines whether the last item read was NULL.

26. What are some advantages of using stored procedures ?
Allows for execution of multiple SQL statements, faster processing, and
simplified development.

27. What are some advantages to using dynamic SQL statements ?
They execute the same SQL statement with different parameters.

28. What is an INOUT parameter ?
A parameter that contains a value going into the procedure but can contain
a different value when the procedure is finished.

29. What is the difference between an IN and OUT parameter ?
IN parameters have values going into the procedure; OUT parameters
have values coming out of the procedure.

30. In what two ways can you specify a column when you use the getxxx( ) method ‘?
By name or by index.

31. On what record is the cursor initially positioned in the ResultSet object ?
The cursor is positioned on a NULL record that is before the first record.
32. What method moves you to the next record in the result set ?
next( ) of ResultSet interface.

33. Is there any way to move the cursor to the previous record? If so, what is it ?
By using previous( ), but supported by JDBC 2.0.

34. What is an Autolncrementing column?
A column that automatically inserts a new number into the colunm.

35. How is the column name different from the column label ?
The column name is the name as listed in the table schema; the label is
what should be displayed to the user

36. What is the precision of a column ?
The number of digits each data value will contain

37. In a Select statement, what does the from clause specify ?
The tables that should be looked through

38. What does the setRow( ) method do ?
Sets the row for the object.

39. How would you determine which row the Select object is currently on ?
The getRow( ) method of ResultSet.

40. What is the difference between specifying colunms and not specifying columns in the first section of the Insert statement ?
Not specifying columns means that you have to include all column data .
values in the correct order

41. Why should you always specify columns in an insert statement ?
So that you will be insulated from database changes

42. What value does the retrieve( ) method return ?
The number of records retrieved

43. What are the four SQL types that are used in the DataUpdate interface ?

44. What method would you use to set the record position to the fifth record ?
setRow( )

45. What value does the getColumnType( ) method return ?
An integer that contains a predefined constant identifying the datatype.

46. List the two ways in which you can move the record position to the initial record ?
first( ) and setRow( )

47. List the two ways in which you can move the record position to the last record.
last( ) and setRow( )

48. What method enables you to change the Connection object ?
setConnection( )

49. How would you get the number of records in the component ?
rowCount( ).

50. What two items must be specified for an update to occur ?
Update the table name and at least one update column.
51. Initially, are the records in the component and the items in the list the same ?

52. What does the setConnection( Connection, boolean) method do ?
Changes the Connection object and resets or doesn’t reset the component
depending on the boolean value.

53. What method would you call to reset the component?
reset( )

54. Why is it important to always close the Statement object after you use it ?
So that the resources used by the object are released back to the system.

55. What is getColumnCount( ) of ResultSetMeta returns ?
The number of columns of the table.

56. What object is used to listen for client connections ?

57. What method connects a client to a server?
accept( ).

58. Can We create an object of J clbcOdbcDriver object ?
Generally, we do not need to create an instance of a driver and register it with the DriverManager because calling Class.forName will do that for us automatically. If we create our own instance, it is only extra labor and creating an unnecessary duplicate; but it would do no harm.

59. In the SQL command we supply to the JDBC, we don’t supply the statement terminator ; .Does it work ? For example observe the following code and does it work ?
smt.executeUpdate(“select *from employee”) ;. Actually to think so , it must be like this:
smt.executeUpdate(“select *t`rom employee;”) ;

This code does not end with a DBMS statement terminator, which can vary from DBMS to DBMS. For example, Oracle uses a semicolon (;) toindicate the end of a statement, and Sybase uses the word go . Theidriver you are using will automatically supply the appropriate statement terminator, and you will not need to include it in your JDBC code.

60. Does it make any difference in writing select as SELECT ?
It does not make any difference because the Oracle keywords(like select, update etc.) are not case—sensitive. But the values are case—sensitive like “SNRao” is different from “snrao”.

61. How to Make Updates to Updatable Result Sets?
Another new feature in the JDBC 2.0 API is the ability to update rows in a result set using methods in the Java programming language rather than having to send an SQL command. But before you can take advantage of this capability, you need to create a ResultSet object that is updatable. In order to do this, you supply the ResultSet constant CONCUR_UPDATABLE to the createStatement method.
Connection con =
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet uprs : stmt,executeQuery(“SELECT COF_NAME, PRICE FROM COFFEES”);

Click Here To More Java Interview Questions

If you have questions, please ask below


  1. Gopal Chandra Garain says:

    what is the difference between
    String s1=new String(“abc”); and
    StringBuffer s1=new StringBuffer(“abc”);

  2. Gopal Chandra Garain says:

    How many types of ResultSet and are they?

Leave a Reply

If you have any questions headover to our forums

You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <code> <em> <strong>