Home Subjects Java Programming JDBC

Java Programming
JDBC

Java OOP, collections, multithreading

25 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 21–25 of 25
Topics in Java Programming
Q.21 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.

Test
Q.22 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.

Test
Q.23 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.

Test
Q.24 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.

Test
Q.25 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=?"

Test
IGET
IGET AI
Online · Exam prep assistant
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