Top MCQs on JDBC (Advanced Java)

31.) Which method allows you to set a timeout for a JDBC query?

A) setQueryTimeout()
B) setStatementTimeout()
C) setConnectionTimeout()
D) JDBC does not support query timeouts

Answer: Option A

Explanation: You can set a timeout for a JDBC query using the setQueryTimeout() method.

32.) In JDBC, what is the purpose of the ResultSetMetaData interface?

A) To retrieve data from a result set
B) To retrieve metadata about the result set, such as column names and types
C) To execute SQL statements
D) To handle transactions

Answer: Option B

Explanation: The ResultSetMetaData interface is used to retrieve metadata about the result set, such as column names and types.

33.) What is a batch update in JDBC?

A) A method for updating database schema
B) A process for executing multiple SQL statements as a single unit
C) An optimized query for retrieving data
D) A way to establish a JDBC connection

Answer: Option B

Explanation: In JDBC, a batch update is a process for executing multiple SQL statements as a single unit, which can improve performance and reduce overhead.

34.) How can you execute a batch update in JDBC?

A) By using a ResultSet object
B) By calling the executeBatch() method of a Statement object
C) By using a PreparedStatement
D) By calling the executeUpdate() method multiple times

Answer: Option B

Explanation: You can execute a batch update in JDBC by calling the executeBatch() method of a Statement object after adding multiple SQL statements to the batch.

35.) What is metadata in the context of JDBC?

A) Data stored in a database table
B) Information about the database, such as its name and version
C) The result set of a SQL query
D) Data encryption in JDBC connections

Answer: Option B

Explanation: Metadata in the context of JDBC refers to information about the database, such as its name, version, and structure.

36.) What does the JDBC DatabaseMetaData interface provide?

A) Information about the database driver
B) Information about the JDBC API
C) Information about the database, such as tables, columns, and schemas
D) Information about SQL query performance

Answer: Option C

Explanation: The JDBC DatabaseMetaData interface provides information about the database, including details about tables, columns, schemas, and more.

37.) What is a SQL join in the context of databases and JDBC?

A) A database connection string
B) A technique for optimizing SQL queries
C) A way to combine data from multiple database tables
D) A method for executing SQL statements in parallel

Answer: Option C

Explanation: In the context of databases and JDBC, a SQL join is a way to combine data from multiple database tables based on a related column or condition.

38.) Which type of SQL join returns only the rows with matching values in both tables?

A) INNER JOIN
B) LEFT JOIN
C) RIGHT JOIN
D) FULL JOIN

Answer: Option A

Explanation: An INNER JOIN in SQL returns only the rows with matching values in both tables being joined.

39.) What is the purpose of the ResultSet.TYPE_SCROLL_INSENSITIVE constant in JDBC?

A) To disable scrolling through a result set
B) To enable scrollable and insensitive result sets
C) To specify the cursor type for a statement
D) To specify the fetch direction for a result set

Answer: Option B

Explanation: The ResultSet.TYPE_SCROLL_INSENSITIVE constant in JDBC is used to specify a scrollable and insensitive result set, allowing for navigation in both directions.

40.) Which method allows you to update rows in a JDBC result set?

A) updateRow()
B) insertRow()
C) deleteRow()
D) modifyRow()

Answer: Option A

Explanation: The updateRow() method in JDBC allows you to update rows in a result set.

Leave a Reply

Your email address will not be published. Required fields are marked *