Java Programming — JDBC
Java OOP, collections, multithreading
100 Questions 10 Topics Take Test
Advertisement
Showing 81–90 of 100 questions in JDBC
Q.81 Easy JDBC
What is the correct syntax to retrieve an integer value from a ResultSet object at column index 2?
A rs.getInt(2);
B rs.getInteger(2);
C rs.fetchInt(2);
D rs.readInt(2);
Correct Answer:  A. rs.getInt(2);
EXPLANATION

The correct method is getInt(int columnIndex) which retrieves an integer value from the ResultSet at the specified column index (1-based indexing).

Take Test
Q.82 Easy JDBC
Which JDBC driver type is platform-independent and does not require native code installation?
A Type 1 Driver
B Type 2 Driver
C Type 3 Driver
D Type 4 Driver
Correct Answer:  D. Type 4 Driver
EXPLANATION

Type 4 drivers (thin drivers) are pure Java drivers that communicate directly with the database using the database native protocol. They are platform-independent and do not require native code.

Take Test
Q.83 Medium JDBC
Which of the following is the correct way to close JDBC resources to prevent resource leaks?
A Close ResultSet, Statement, then Connection
B Close Connection only
C Use try-with-resources statement
D Both A and C are correct
Correct Answer:  D. Both A and C are correct
EXPLANATION

Resources should be closed in reverse order of creation (ResultSet → Statement → Connection), or preferably using try-with-resources which auto-closes resources.

Take Test
Q.84 Hard JDBC
In JDBC, what does the ResultSet.TYPE_SCROLL_INSENSITIVE constant represent?
A Non-scrollable result set
B Scrollable result set that doesn't reflect database changes
C Forward-only result set
D Bidirectional result set
Correct Answer:  B. Scrollable result set that doesn't reflect database changes
EXPLANATION

TYPE_SCROLL_INSENSITIVE creates scrollable ResultSet (can move forward/backward) but changes made to database after ResultSet creation are not reflected.

Take Test
Q.85 Hard JDBC
Which JDBC feature allows you to call stored procedures?
A Statement
B PreparedStatement
C CallableStatement
D ExecutableStatement
Correct Answer:  C. CallableStatement
EXPLANATION

CallableStatement is used to invoke stored procedures and functions. It extends PreparedStatement and supports IN, OUT, and INOUT parameters.

Take Test
Q.86 Hard JDBC
What is the difference between execute(), executeQuery(), and executeUpdate()?
A execute() returns boolean, executeQuery() returns ResultSet, executeUpdate() returns int
B All three are identical
C execute() is fastest, others are slower
D executeQuery() updates database, executeUpdate() retrieves data
Correct Answer:  A. execute() returns boolean, executeQuery() returns ResultSet, executeUpdate() returns int
EXPLANATION

execute() returns boolean (true if ResultSet available), executeQuery() returns ResultSet for SELECT, executeUpdate() returns row count for INSERT/UPDATE/DELETE.

Take Test
Q.87 Hard JDBC
How would you implement batch processing in JDBC for multiple INSERT operations?
A Use addBatch() and executeBatch() methods
B Execute each insert in a loop separately
C Use multiple connections
D Create multiple statements
Correct Answer:  A. Use addBatch() and executeBatch() methods
EXPLANATION

addBatch() adds SQL command to batch, executeBatch() executes all batched commands at once, improving performance significantly for multiple operations.

Take Test
Q.88 Hard JDBC
Consider code: String query = "SELECT * FROM users WHERE id=" + userId; stmt.executeQuery(query); What security issue exists?
A Performance degradation
B SQL Injection vulnerability
C Memory leak
D Connection timeout
Correct Answer:  B. SQL Injection vulnerability
EXPLANATION

This is vulnerable to SQL injection as user input is directly concatenated. Using PreparedStatement with parameters prevents this: "SELECT * FROM users WHERE id=?"

Take Test
Q.89 Medium JDBC
What does the setAutoCommit(false) method do in JDBC?
A Disables automatic transaction commit
B Enables automatic transaction commit
C Rolls back current transaction
D Closes the connection
Correct Answer:  A. Disables automatic transaction commit
EXPLANATION

setAutoCommit(false) disables automatic commit, allowing multiple statements to be part of single transaction. Manual commit() or rollback() must be called.

Take Test
Q.90 Medium JDBC
Which DriverManager method is used to establish a database connection?
A createConnection()
B getConnection()
C establishConnection()
D openConnection()
Correct Answer:  B. getConnection()
EXPLANATION

DriverManager.getConnection() is the standard method that takes URL, username, and password to establish a connection to the database.

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