MCQs > IT & Programming > JDBC MCQs > Basic JDBC MCQs

Basic JDBC MCQ

1. Consider the following statement:

PreparedStatement ps=con.prepareStatement("INSERT INTO ORDER (CUSTOMER_ID ,PRICE) VALUES(?,?)");

Which of the following should come after this statement?



Answer

Correct Answer: ps.clearParameters(); ps.setInt(1,3); ps.setDouble(2,790.50); ps.executeUpdate(); 

Note: This Question is unanswered, help us to find answer for this one

2. Which of the following methods eliminates the need to call wasNull() method to handle null database fields?


Answer

Correct Answer: getObject();

Note: This Question is unanswered, help us to find answer for this one

3. Which type of statement object will you use to execute a stored procedure?


Answer

Correct Answer: CallableStatement

Note: This Question is unanswered, help us to find answer for this one

4. You have to handle an erroneous situation in a transaction. Which method comes handy in this case?


Answer

Correct Answer: con.rollback();

Note: This Question is unanswered, help us to find answer for this one

5. The code segment below defines a query:

String qry="SELECT CUS_NAME, PRICE FROM CUSTOMER";

Which of the following code snippets will create a scrollable ResultSet?



Answer

Correct Answer: Statement st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); <br>ResultSet srs=st.executeQuery(qry);<br>

Note: This Question is unanswered, help us to find answer for this one

6. Which of the following JDBC methods is used for retrieving large binary objects?


Answer

Correct Answer: getBinaryStream

Note: This Question is unanswered, help us to find answer for this one

7. A user leaves an online shopping cart without checking out. Which of following interfaces will notify to Rollback the transaction?


Answer

Correct Answer: HttpSessionBindingListener

Note: This Question is unanswered, help us to find answer for this one

8. When you are handling user-submitted SQL, you may retrieve a ResultSet or a count. Which of the following methods is handy in this situation?


Answer

Correct Answer: execute()

Note: This Question is unanswered, help us to find answer for this one

9. You need to use a third party driver for establishing a connection with the database. The subprotocol is "webx" and the DSN is "webdsn". What is the syntax of the URL?


Answer

Correct Answer: jdbc:webx:webdsn

Note: This Question is unanswered, help us to find answer for this one

10. You want to execute the following query string, using the connection named "con":

String query = "SELECT * FROM CUSTOMER";

What should the syntax be?



Answer

Correct Answer: Statement stmt=con.createStatement(); <br>ResultSet rs=stmt.executeQuery(query);

Note: This Question is unanswered, help us to find answer for this one

11. After executing the following code, resultvar contains false. What should the next step be?

boolean resultvar=stmt.execute(sql);


Answer

Correct Answer: stmt.getResultSet();

Note: This Question is unanswered, help us to find answer for this one

12. Which of the following is not true?


Answer

Correct Answer: CallableStatement cannot take INOUT parameters 

Note: This Question is unanswered, help us to find answer for this one

13. Which of the following is the syntax for creating a CallableStatement?


Answer

Correct Answer: CallableStatement cs=con.prepareCall("{call SHOW_ORDER}")

Note: This Question is unanswered, help us to find answer for this one

14. Your project leader has given you a new task. You have to work on a module in which the transaction has to be extended across multiple page requests and multiple servlets. How will you implement this?


Answer

Correct Answer: By session tracking and using HttpSession to hold a connection for each user

Note: This Question is unanswered, help us to find answer for this one

15. Will the below script execute properly?

1.CREATE TABLE CUSTOMER        
2.(
3.CUS_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, SALES INTEGER
4.)



Answer

Correct Answer: Yes. The table will be created successfully.

Note: This Question is unanswered, help us to find answer for this one

16. How do you register a JDBC driver?


Answer

Correct Answer: Class.forName("driver");

Note: This Question is unanswered, help us to find answer for this one

17. You are trying to connect to a database through JDBC. There is a problem with one of the methods immediately after the driver has been loaded. Which exception will be thrown?


Answer

Correct Answer: SQLException

Note: This Question is unanswered, help us to find answer for this one

18. Name the interface you will use to retrieve the underlying structure of the query result:


Answer

Correct Answer: ResultSetMetaData

Note: This Question is unanswered, help us to find answer for this one

19. You are developing a shopping cart for your client. Where would you like to put your business logic?


Answer

Correct Answer: In middleware servlets

Note: This Question is unanswered, help us to find answer for this one

20. You want to start a transaction for bank account processing. Which of the following methods will you execute on the Connection object to begin it?



Answer

Correct Answer: con.setAutoCommit(false);

Note: This Question is unanswered, help us to find answer for this one

21. Which of the following methods will you use to execute INSERT, UPDATE and DELETE SQL statements?


Answer

Correct Answer: executeUpdate();

Note: This Question is unanswered, help us to find answer for this one

22. What should the syntax be to establish a connection with a Database?


Answer

Correct Answer: Connection con = DriverManager.getConnection(url,"myLogin", "myPassword");

Note: This Question is unanswered, help us to find answer for this one

23. ResultSet objects follow index patterns of:


Answer

Correct Answer: RDBMS standard

Note: This Question is unanswered, help us to find answer for this one

24. You executed a query to retrieve 40 products from the database and obtained a scrollable ResultSet named 'scrollrs'. You started scrolling the ResultSet as follows:

scrollrs.next();
scrollrs.absolute(-10);
scrollrs.relative(-6);

At which row number is the cursor currently located?


Answer

Correct Answer: 24

Note: This Question is unanswered, help us to find answer for this one

25. Your project leader has asked you to improve the performance of JDBC connectivity by reusing objects in your Servlet's code. Which of the following is an appropriate solution?


Answer

Correct Answer: Reuse the database connection and use PreparedStatement objects with synchronized blocks

Note: This Question is unanswered, help us to find answer for this one

26. Which of the following is not true for a ResultSet?


Answer

Correct Answer: Methods next() and previous() return -1 beyond the ResultSet

Note: This Question is unanswered, help us to find answer for this one

27. You want to execute a CallableStatement named 'cs'. It is expected to return multiples results. Which of the following methods will you choose?


Answer

Correct Answer: ResultSet rs=cs.execute()

Note: This Question is unanswered, help us to find answer for this one

28. How will you create a new instance of a JDBC driver explicitly?


Answer

Correct Answer: Class.forName("driver").newInstance(); 

Note: This Question is unanswered, help us to find answer for this one

29. A process allows you to group multiple SQL statements. Commit or Rollback can be performed on the group together. This process is known as:


Answer

Correct Answer: Transaction

Note: This Question is unanswered, help us to find answer for this one

30. Which JDBC driver is considered best in terms of performance and efficiency?


Answer

Correct Answer: Type-4 Driver

Note: This Question is unanswered, help us to find answer for this one

31. Which exception will be thrown in your code, if the specified driver could not be loaded?


Answer

Correct Answer: ClassNotFoundException

Note: This Question is unanswered, help us to find answer for this one

32. Please select all the correct options. JDBC Driver Manager is:


Answer

Correct Answer: Able to activate registered drivers

Note: This Question is unanswered, help us to find answer for this one

33. Java Database Connectivity (JDBC) is a:


Answer

Correct Answer: Database-independent API

Note: This Question is unanswered, help us to find answer for this one

34. You have obtained a scrollable ResultSet named 'srs' by executing a query. Which of the following methods will you use to verify the position of the cursor?


Answer

Correct Answer: srs.getRow()

Note: This Question is unanswered, help us to find answer for this one

35. SQLException has a method, which provides the feature of chaining or encapsulation of additional Exception objects. Identify the method from the following:


Answer

Correct Answer: getNextException()

Note: This Question is unanswered, help us to find answer for this one

36. You have obtained a ResultSet object named 'rs' after executing the following query:

SELECT * FROM CUSTOMER

Which loop can you use to return all the records in the ResultSet?



Answer

Correct Answer: while(rs.next())

Note: This Question is unanswered, help us to find answer for this one

37. Under which category does the following driver fall:

WebLogic's Tengah "all Java Type-3 driver"



Answer

Correct Answer: Net-Protocol All-Java Driver

Note: This Question is unanswered, help us to find answer for this one

38. JDBC is based on:


Answer

Correct Answer: X/Open CLI (Call Level Interface)

Note: This Question is unanswered, help us to find answer for this one

39. SQLWarning object deals with database access warnings. It is a subclass of:


Answer

Correct Answer: SQLException

Note: This Question is unanswered, help us to find answer for this one

40. Open Database Connectivity is:


Answer

Correct Answer: Platform dependent

Note: This Question is unanswered, help us to find answer for this one

41. A warning can be thrown by a Connection object, a Statement object or a  ResultSet object. Which method is used to retrieve the warning:


Answer

Correct Answer: getWarnings()

Note: This Question is unanswered, help us to find answer for this one

42. Transactions have a property called atomicity, which means:


Answer

Correct Answer: Everything takes place once

Note: This Question is unanswered, help us to find answer for this one

43.

Servlet developers should avoid using JDBC-ODBC bridge driver because:

Answer

Correct Answer: The driver is of Type-1

Note: This Question is unanswered, help us to find answer for this one

44.

ResultSet objects follow index patterns of:

Answer

Correct Answer: Array standard

Note: This Question is unanswered, help us to find answer for this one

45.

Which of the following methods eliminates the need to call wasNull() method to handle null database fields?

Answer

Correct Answer: getInt();

Note: This Question is unanswered, help us to find answer for this one

46.

Open Database Connectivity is:

Answer

Correct Answer: Platform independent

Note: This Question is unanswered, help us to find answer for this one

47. A ______ RowSet object makes a connection to a data source only to read or write data based on a ResultSet object.

Answer

Correct Answer: disconnected

Note: This Question is unanswered, help us to find answer for this one

48. True or False? A transaction is finished when commit() or rollback() is called on the Transaction object.

Answer

Correct Answer: False

Note: This Question is unanswered, help us to find answer for this one

49. Resources used by Blob, Clob an NClob Java objects can be released by using which method?

Answer

Correct Answer: free

Note: This Question is unanswered, help us to find answer for this one

50. If your Java aplication is accessing multiple databases at the same time, the preferred driver type is:

Answer

Correct Answer: Type 3: JDBC-Net pure Java

Note: This Question is unanswered, help us to find answer for this one

51. General SQL escape syntax format is:

Answer

Correct Answer: {keyword 'parameters'}

Note: This Question is unanswered, help us to find answer for this one

52. True or False? The list associated with a Statement object may contain a statement that produces a ResultSet object.

Answer

Correct Answer: False

Note: This Question is unanswered, help us to find answer for this one

53. For storing file into the database, which datatype is used in table?

Answer

Correct Answer: CLOB

Note: This Question is unanswered, help us to find answer for this one

54. True or False? Applications may release Blob, Clob, and NClob resources by invoking their release method.

Answer

Correct Answer: False

Note: This Question is unanswered, help us to find answer for this one

55. True or False? After fetching an instance of the Connection object, a live connection must first be established before making queries to the database.

Answer

Correct Answer: False

Note: This Question is unanswered, help us to find answer for this one

56. The _______ of a ResultSet object determines what level of update functionality is supported.

Answer

Correct Answer: concurrency

Note: This Question is unanswered, help us to find answer for this one

57. Which of the following is not an Advanced Data type in JDBC API?

Answer

Correct Answer: varbinary (max)

Note: This Question is unanswered, help us to find answer for this one

58. True or False? MySQL and Java DB support the ARRAY SQL data type.

Answer

Correct Answer: False

Note: This Question is unanswered, help us to find answer for this one

59. Which driver type is best suited for development and testing purpose?

Answer

Correct Answer: Type 1: JDBC-ODBC Driver Bridge

Note: This Question is unanswered, help us to find answer for this one

60. _______ is NOT a valid example of a transaction isolation level.

Answer

Correct Answer: TRANSACTION_REPEATABLE_COMMIT

Note: This Question is unanswered, help us to find answer for this one

61. The DATALINK SQL data type maps to the JDBC _____ object.

Answer

Correct Answer: java.net.URL

Note: This Question is unanswered, help us to find answer for this one

62. Which object has the ability to use input and output streams to supply parameter data?

Answer

Correct Answer: PreparedStatement

Note: This Question is unanswered, help us to find answer for this one

63. A _______ is a set of one or more statements that is executed as a unit.

Answer

Correct Answer: transaction

Note: This Question is unanswered, help us to find answer for this one

64. Which of the following parameters is used by the Preparedstatement object?

Answer

Correct Answer: IN

Note: This Question is unanswered, help us to find answer for this one

65. If you are going to use Static SQL statements at runtime, the best JDBC interface to use is:

Answer

Correct Answer: Statememt

Note: This Question is unanswered, help us to find answer for this one

66. Transaction_read_committed (one example of transaction isolation level) does not alow:

Answer

Correct Answer: Dirty reads

Note: This Question is unanswered, help us to find answer for this one

67. _______ driver type(s) can be used in a three-tier architecture and if the web server and DBMS are running on the same machine.

Answer

Correct Answer: Type 1, 2, 3, and 4

Note: This Question is unanswered, help us to find answer for this one

68. _______ JDBC driver type(s) can be used in either applet or servlet code.

Answer

Correct Answer: Type 3 and 4

Note: This Question is unanswered, help us to find answer for this one

69. _______ driver type(s) are for use over communication networks.

Answer

Correct Answer: Type 3 and 4

Note: This Question is unanswered, help us to find answer for this one

70. True or False? JDBC is an API to connect object and XML data sources.

Answer

Correct Answer: False

Note: This Question is unanswered, help us to find answer for this one

71. A _______ is used to access the data in a ResultSet.

Answer

Correct Answer: cursor

Note: This Question is unanswered, help us to find answer for this one

72. ________ is NOT a step you must perform to process an SQL statement.

Answer

Correct Answer: Ping the data source.

Note: This Question is unanswered, help us to find answer for this one

73. Autocommit must be set to false when using batch processing with Statement object? True or Flase

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

74. In order to undo the previous transaction, use

Answer

Correct Answer: rollback

Note: This Question is unanswered, help us to find answer for this one

75. The most common exception you'll deal with JDBC:

Answer

Correct Answer: SQLException

Note: This Question is unanswered, help us to find answer for this one

76. In the syntax {ts 'yyyy-mm-dd hh:mm:ss'}, ts stands for

Answer

Correct Answer: timestamp

Note: This Question is unanswered, help us to find answer for this one

77. You must register your JDBC driver in your program before using it? True or False

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

78. True or False? JDBC will work with many different database management systems.

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

79. What kind of database is the command jdbc:mysql:://localhost:3306/ is connecting to?

Answer

Correct Answer: MySQL

Note: This Question is unanswered, help us to find answer for this one

80. JDBC stands for _______.

Answer

Correct Answer: Java Database Connectivity

Note: This Question is unanswered, help us to find answer for this one

81. If a database operation fails, JDBC raises an:

Answer

Correct Answer: SQLException

Note: This Question is unanswered, help us to find answer for this one

82. In order to commit changes to the database, use:

Answer

Correct Answer: commit

Note: This Question is unanswered, help us to find answer for this one

83. The SQLXML interface provides the _____ method to access its internal content.

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

84. Which of the following is NOT needed to set up a JDBC Environment:

Answer

Correct Answer: .Net

Note: This Question is unanswered, help us to find answer for this one

85. A ______ object lets you access the data returned by an SQL statement.

Answer

Correct Answer: ResultSet

Note: This Question is unanswered, help us to find answer for this one

86. If the ResultSet type is TYPE_FORWARD_ONLY, it implies:

Answer

Correct Answer: the cursor can move forward in the result set

Note: This Question is unanswered, help us to find answer for this one

87. The Class.forname() method is used to:

Answer

Correct Answer: register the jdbc driver

Note: This Question is unanswered, help us to find answer for this one

88. If the column you are interested in viewing contains an int, which of the following methods of Resultset can be used?

Answer

Correct Answer: getInt()

Note: This Question is unanswered, help us to find answer for this one

89. _______ extends the RowSet interface.

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

90. True or False? If executing a Statement object many times, a PreparedStement object will reduce execution time.

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

91. When a Driver Class is loaded, it creates an instance of itself and registers it with:

Answer

Correct Answer: DriverManager

Note: This Question is unanswered, help us to find answer for this one

92. At the end of the JDBC program, it is explicity required to close al the connections to the database? True or False

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

93. In the command jdbc:derby:testdb;create=true, testdb stands for

Answer

Correct Answer: Database name

Note: This Question is unanswered, help us to find answer for this one

94. Which of the following in not required by the getConnection() method to create a connecton object?

Answer

Correct Answer: Website url

Note: This Question is unanswered, help us to find answer for this one

95. {fn length('Friday')} will return

Answer

Correct Answer: 6

Note: This Question is unanswered, help us to find answer for this one

96. In order to accept input parameters at runtime, use the following JDBC interface:

Answer

Correct Answer: PreparedStatement

Note: This Question is unanswered, help us to find answer for this one

97. True or False? The default mode when a connection is created is auto-commit mode.

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

98. True or False? A transaction is closed when close() is called on the Connection object.

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

99. True or False? JDBC is an API to access relational databases, spreadsheets, and flat files.

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

100. To close existing database connections, you should call

Answer

Correct Answer: close() method

Note: This Question is unanswered, help us to find answer for this one

101. JDBC API uses which drivers to connect to the database?

Answer

Correct Answer: jdbc

Note: This Question is unanswered, help us to find answer for this one

102. True or False? The RowSet object holds data in a tabular form that is more flexible and easier to use than the ResultSet object.

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

103. ______ is NOT a valid parameter mode for a stored procedure.

Answer

Correct Answer: CONSTANT

Note: This Question is unanswered, help us to find answer for this one

104. ________ is an object used for precompiling SQL statements that may contain input parameters.

Answer

Correct Answer: Prepared Statement

Note: This Question is unanswered, help us to find answer for this one

105. All JDBC Rowset objects are derived from which interface?

Answer

Correct Answer: ResultSet

Note: This Question is unanswered, help us to find answer for this one

106. The executeUpdate method from Statement returns:

Answer

Correct Answer: an integer representing the number of rows affected by the SQL statement

Note: This Question is unanswered, help us to find answer for this one

107. A ________ is used to mark intermediate points inside a transaction in order to get a more fine-grained control.

Answer

Correct Answer: savepoint

Note: This Question is unanswered, help us to find answer for this one

108. To jump back to a specific point in the program, create a:

Answer

Correct Answer: Savepoint

Note: This Question is unanswered, help us to find answer for this one

109. A ______ is not contained in an SQLException.

Answer

Correct Answer: effect

Note: This Question is unanswered, help us to find answer for this one

110. Which of the following is not an overloaded DriverManager.getConnection () method?

Answer

Correct Answer: getConnections()

Note: This Question is unanswered, help us to find answer for this one

111. In order to access Database stored procedures, the best JDBC interface is:

Answer

Correct Answer: CallableStatement

Note: This Question is unanswered, help us to find answer for this one

112. The _______ method adds SQL commands to the list associated with a Statement object.

Answer

Correct Answer: addBatch

Note: This Question is unanswered, help us to find answer for this one

113. public void updateString(int columnIndex, String s) throws SQLException

Answer

Correct Answer: Changes the String in the specified column specified by its index to the value of s

Note: This Question is unanswered, help us to find answer for this one

114. A ________ is a subclass of SQLException.

Answer

Correct Answer: SQLWarning

Note: This Question is unanswered, help us to find answer for this one

115. _______ is not a valid ResultSet type.

Answer

Correct Answer: TYPE_BACKWARD_ONLY

Note: This Question is unanswered, help us to find answer for this one

116. While accessing databses such as Oracle, Sybase or IBM, the preferred driver type is:

Answer

Correct Answer: Type 4: 100% Pure Java

Note: This Question is unanswered, help us to find answer for this one

117. ______ is NOT a subclass of SQLException

Answer

Correct Answer: SQLFailureException

Note: This Question is unanswered, help us to find answer for this one

118. _______ is not a method of a ResultSet cursor.

Answer

Correct Answer: end

Note: This Question is unanswered, help us to find answer for this one

119. JDBC is an API for the _________ programming language.

Answer

Correct Answer: Java

Note: This Question is unanswered, help us to find answer for this one