Java Programming — JDBC
Java OOP, collections, multithreading
100 Questions 10 Topics Take Test
Advertisement
Showing 31–40 of 100 questions in JDBC
Q.31 Medium JDBC
What happens if you call next() on a ResultSet after the last row?
A Throws SQLException
B Returns false
C Returns true
D Throws NoSuchElementException
Correct Answer:  B. Returns false
EXPLANATION

next() returns false when the cursor is positioned beyond the last row, indicating no more rows available.

Take Test
Q.32 Medium JDBC
Which statement should be used when you need to retrieve column information without executing multiple queries?
A Statement with multiple executeQuery()
B PreparedStatement
C ResultSetMetaData
D DatabaseMetaData
Correct Answer:  C. ResultSetMetaData
EXPLANATION

ResultSetMetaData provides column information directly from the ResultSet without additional queries.

Take Test
Q.33 Medium JDBC
What is the difference between execute() and executeUpdate() methods?
A execute() returns boolean, executeUpdate() returns int
B execute() can execute any SQL statement, executeUpdate() only for DML
C Both A and B are correct
D There is no difference
Correct Answer:  C. Both A and B are correct
EXPLANATION

execute() returns true/false and handles any SQL, while executeUpdate() returns affected rows count for DML statements only.

Take Test
Q.34 Medium JDBC
In JDBC, which class is used to retrieve database metadata information?
A ResultSet
B Statement
C DatabaseMetaData
D Connection
Correct Answer:  C. DatabaseMetaData
EXPLANATION

DatabaseMetaData provides information about the database, tables, columns, and other database properties.

Take Test
Q.35 Medium JDBC
What does ResultSetMetaData.getColumnCount() return?
A Number of rows in ResultSet
B Number of columns in ResultSet
C Column data type
D Column name
Correct Answer:  B. Number of columns in ResultSet
EXPLANATION

getColumnCount() returns the total number of columns present in the ResultSet.

Take Test
Advertisement
Q.36 Medium JDBC
What is the benefit of using PreparedStatement over Statement for repeated queries?
A Faster execution due to pre-compilation
B Automatic SQL injection prevention
C Better readability of code
D Both A and B
Correct Answer:  D. Both A and B
EXPLANATION

PreparedStatement offers both pre-compilation for performance and SQL injection prevention through parameterized queries.

Take Test
Q.37 Medium JDBC
Which JDBC method executes UPDATE, INSERT, or DELETE statements?
A executeQuery()
B execute()
C executeUpdate()
D executeBatch()
Correct Answer:  C. executeUpdate()
EXPLANATION

executeUpdate() executes DML statements and returns the number of rows affected.

Take Test
Q.38 Medium JDBC
What is the purpose of Connection.commit() in JDBC?
A Close the connection
B Save all changes made in the current transaction
C Rollback transactions
D Create a new statement
Correct Answer:  B. Save all changes made in the current transaction
EXPLANATION

commit() saves all changes made during the current transaction permanently to the database.

Take Test
Q.39 Easy JDBC
In JDBC, what does the executeQuery() method return?
A int
B boolean
C ResultSet
D void
Correct Answer:  C. ResultSet
EXPLANATION

executeQuery() returns a ResultSet containing the rows fetched from the database for SELECT queries.

Take Test
Q.40 Easy JDBC
What exception is thrown when a database connection fails in JDBC?
A IOException
B SQLException
C ClassNotFoundException
D NullPointerException
Correct Answer:  B. SQLException
EXPLANATION

SQLException is thrown when database-related errors occur, including connection failures and SQL execution errors.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips