Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

958 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 311–320 of 958
Topics in Java Programming
Q.311 Medium JDBC
What happens when Connection.setAutoCommit(false) is called in JDBC?
A Auto-commit is enabled immediately
B Manual transaction control is enabled; changes require explicit commit
C All pending transactions are rolled back
D The connection is closed automatically
Correct Answer:  B. Manual transaction control is enabled; changes require explicit commit
EXPLANATION

Setting autoCommit to false enables manual transaction management where commit() must be explicitly called.

Take Test
Q.312 Medium JDBC
Which JDBC method is used to set an input parameter in a PreparedStatement?
A setParameter()
B setInt(), setString(), etc.
C bindParameter()
D addParameter()
Correct Answer:  B. setInt(), setString(), etc.
EXPLANATION

PreparedStatement uses type-specific setter methods like setInt(), setString(), setDate() to bind parameters.

Take Test
Q.313 Medium JDBC
What is the difference between ResultSet.TYPE_SCROLL_INSENSITIVE and ResultSet.TYPE_SCROLL_SENSITIVE?
A Insensitive is faster; Sensitive allows concurrent updates visibility
B Insensitive allows backward navigation; Sensitive does not
C Sensitive is read-only; Insensitive allows modifications
D They are identical and can be used interchangeably
Correct Answer:  A. Insensitive is faster; Sensitive allows concurrent updates visibility
EXPLANATION

TYPE_SCROLL_INSENSITIVE doesn't reflect concurrent database changes, while TYPE_SCROLL_SENSITIVE may reflect such changes.

Take Test
Q.314 Medium JDBC
In a JDBC batch operation, what does executeBatch() return?
A A ResultSet object
B An array of integers representing update counts
C A single integer value
D A boolean value
Correct Answer:  B. An array of integers representing update counts
EXPLANATION

executeBatch() returns an int array where each element represents the number of rows affected by each statement in the batch.

Take Test
Q.315 Medium JDBC
Which JDBC method is used to retrieve metadata information about the database?
A getMetaData()
B getDatabaseInfo()
C getConnection().getInfo()
D getProperties()
Correct Answer:  A. getMetaData()
EXPLANATION

Connection.getMetaData() returns a DatabaseMetaData object containing information about the database and driver.

Take Test
Q.316 Easy JDBC
What is the purpose of the Connection.commit() method in JDBC?
A To establish a new database connection
B To permanently save all changes made in the current transaction
C To execute the next SQL statement
D To close the database connection
Correct Answer:  B. To permanently save all changes made in the current transaction
EXPLANATION

commit() finalizes the transaction and persists all changes made since the last commit or rollback.

Take Test
Q.317 Easy JDBC
In JDBC, which exception is thrown when the database driver class is not found?
A SQLException
B ClassNotFoundException
C DriverNotFoundException
D DatabaseException
Correct Answer:  B. ClassNotFoundException
EXPLANATION

ClassNotFoundException is thrown when Class.forName() cannot locate the JDBC driver class.

Take Test
Q.318 Easy JDBC
What does the DriverManager.getConnection() method return?
A A Statement object
B A Connection object
C A ResultSet object
D A DatabaseMetaData object
Correct Answer:  B. A Connection object
EXPLANATION

DriverManager.getConnection() establishes a connection to the database and returns a Connection object.

Take Test
Q.319 Easy JDBC
Which JDBC method is used to retrieve the number of rows affected by an INSERT, UPDATE, or DELETE statement?
A getRowCount()
B executeUpdate()
C getUpdateCount()
D fetchSize()
Correct Answer:  B. executeUpdate()
EXPLANATION

executeUpdate() returns an int representing the number of rows affected by the SQL statement execution.

Take Test
Q.320 Easy JDBC
What is the primary advantage of using PreparedStatement over Statement in JDBC?
A Better performance and protection against SQL injection
B Ability to execute multiple queries simultaneously
C Automatic connection pooling
D Direct transaction management
Correct Answer:  A. Better performance and protection against SQL injection
EXPLANATION

PreparedStatement pre-compiles SQL and uses parameterized queries, preventing SQL injection and improving performance.

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