Home Subjects Java Programming JDBC

Java Programming
JDBC

Java OOP, collections, multithreading

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

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

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

Test
Q.44 Medium JDBC
What is the primary advantage of using PreparedStatement over Statement?
A Faster execution and SQL injection prevention
B Larger result set size
C Better memory management
D Automatic type conversion
Correct Answer:  A. Faster execution and SQL injection prevention
EXPLANATION

PreparedStatement offers faster execution due to precompilation and prevents SQL injection through parameterized queries using placeholders (?).

Test
Q.45 Medium JDBC
Which interface is used to execute precompiled SQL statements in JDBC?
A Statement
B PreparedStatement
C CallableStatement
D BatchStatement
Correct Answer:  B. PreparedStatement
EXPLANATION

PreparedStatement is used for precompiled SQL statements with parameters. It provides better performance and prevents SQL injection compared to Statement.

Test
Q.46 Medium JDBC
What does the executeUpdate() method return in JDBC?
A A ResultSet object
B Number of rows affected
C A boolean value
D Query execution time
Correct Answer:  B. Number of rows affected
EXPLANATION

executeUpdate() returns an integer representing the number of rows affected by INSERT, UPDATE, or DELETE operations. executeQuery() returns ResultSet.

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