Showing 51–60 of 100 questions
in JDBC
Which JDBC constant specifies read-only access for a ResultSet?
A
ResultSet.CONCUR_READ_ONLY
B
ResultSet.TYPE_READ_ONLY
C
ResultSet.MODE_READ
D
ResultSet.ACCESS_READ_ONLY
Correct Answer:
A. ResultSet.CONCUR_READ_ONLY
EXPLANATION
CONCUR_READ_ONLY is the concurrency constant that specifies a read-only ResultSet.
In JDBC, what is the purpose of the ResultSetMetaData interface?
A
To execute SQL queries
B
To retrieve information about the structure of a ResultSet
C
To manage database connections
D
To handle transaction management
Correct Answer:
B. To retrieve information about the structure of a ResultSet
EXPLANATION
ResultSetMetaData provides information about columns, data types, and column properties of a ResultSet.
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.
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.
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.
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.
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.
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.
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.
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.