Java Programming — JDBC
Java OOP, collections, multithreading
100 Questions 10 Topics Take Test
Advertisement
Showing 21–30 of 100 questions in JDBC
Q.21 Medium JDBC
Which JDBC driver type is considered the most portable across different databases?
A Type 1 - JDBC-ODBC Bridge
B Type 2 - Native API Driver
C Type 3 - Network Protocol Driver
D Type 4 - Thin Driver
Correct Answer:  D. Type 4 - Thin Driver
EXPLANATION

Type 4 drivers are pure Java implementations that directly communicate with the database, making them platform-independent and most portable.

Take Test
Q.22 Easy JDBC
In JDBC, what does the BatchUpdate feature allow developers to do?
A Execute single queries faster
B Execute multiple queries in a single batch for improved performance
C Create backup of database
D Monitor database connections
Correct Answer:  B. Execute multiple queries in a single batch for improved performance
EXPLANATION

addBatch() and executeBatch() methods allow multiple SQL statements to be grouped and executed together, reducing network traffic and improving performance.

Take Test
Q.23 Easy JDBC
Which method of Connection interface is used to start a transaction in JDBC?
A setAutoCommit(false)
B beginTransaction()
C startTransaction()
D createTransaction()
Correct Answer:  A. setAutoCommit(false)
EXPLANATION

setAutoCommit(false) disables auto-commit mode, allowing manual control over transactions through commit() and rollback() methods.

Take Test
Q.24 Easy JDBC
What is the correct sequence to establish a JDBC connection in Java?
A Load Driver → Create Connection → Execute Query → Close Connection
B Create Connection → Load Driver → Execute Query → Close Connection
C Load Driver → Create Statement → Execute Query → Close Connection
D Create Statement → Load Driver → Create Connection → Execute Query
Correct Answer:  A. Load Driver → Create Connection → Execute Query → Close Connection
EXPLANATION

The correct JDBC connection sequence is: Class.forName() → DriverManager.getConnection() → Create Statement → Execute Query → Close resources.

Take Test
Q.25 Easy JDBC
Which interface in JDBC is used to execute parameterized queries and prevent SQL injection attacks?
A Statement
B PreparedStatement
C CallableStatement
D Connection
Correct Answer:  B. PreparedStatement
EXPLANATION

PreparedStatement is used for parameterized queries with placeholders (?), which prevents SQL injection by separating SQL logic from data.

Take Test
Advertisement
Q.26 Hard JDBC
When using JDBC with Spring Framework in 2024-25, which approach is recommended for resource management?
A Manual try-catch blocks
B Try-with-resources statement
C JdbcTemplate with Spring
D DriverManager only
Correct Answer:  C. JdbcTemplate with Spring
EXPLANATION

JdbcTemplate in Spring Framework automatically manages JDBC resources and is the recommended approach in modern applications.

Take Test
Q.27 Hard JDBC
In JDBC, what is the significance of setting FetchSize on a Statement when dealing with large ResultSets?
A It determines the maximum number of rows to fetch from database in one round-trip
B It sets the total memory allocated for ResultSet
C It automatically closes the ResultSet
D It enables caching of all rows in memory
Correct Answer:  A. It determines the maximum number of rows to fetch from database in one round-trip
EXPLANATION

FetchSize controls how many rows are fetched from the database at once, optimizing performance for large datasets.

Take Test
Q.28 Hard JDBC
Which JDBC feature should be used for executing multiple SQL statements in a batch for optimal performance?
A executeUpdate() in a loop
B executeBatch() with addBatch()
C execute() method
D Multiple Statement objects
Correct Answer:  B. executeBatch() with addBatch()
EXPLANATION

executeBatch() with addBatch() reduces network round-trips and improves performance for bulk operations.

Take Test
Q.29 Hard JDBC
In a JDBC application, when using transactions with setAutoCommit(false), what happens to intermediate savepoints if rollback() is called?
A All changes are saved
B Only savepoint changes are rolled back
C All changes since last commit are rolled back
D The entire connection is closed
Correct Answer:  C. All changes since last commit are rolled back
EXPLANATION

When rollback() is called without savepoints, all changes made since the last commit are undone and rolled back.

Take Test
Q.30 Hard JDBC
Consider a scenario: A developer uses Statement with user input directly in SQL queries. What is the primary risk?
A Slower query execution
B SQL Injection attacks
C Memory leaks
D Connection timeout
Correct Answer:  B. SQL Injection attacks
EXPLANATION

Direct concatenation of user input in SQL queries exposes the application to SQL injection attacks. PreparedStatement should be used instead.

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