Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

958 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 341–350 of 958
Topics in Java Programming
Q.341 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.342 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.343 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.344 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.345 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.346 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.347 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.348 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
Q.349 Medium JDBC
What is Connection pooling in JDBC?
A Storing multiple database connections in a pool for reuse
B Combining multiple queries into one
C Creating backup connections
D Automatic connection switching
Correct Answer:  A. Storing multiple database connections in a pool for reuse
EXPLANATION

Connection pooling maintains a pool of reusable database connections to improve performance and reduce overhead of creating new connections repeatedly.

Take Test
Q.350 Medium JDBC
Which method must be called to move cursor to the next row in ResultSet?
A next()
B moveNext()
C advance()
D fetch()
Correct Answer:  A. next()
EXPLANATION

The next() method moves the ResultSet cursor to the next row and returns true if a row exists, false if no more rows. It's essential for iterating through results.

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