Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

958 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 321–330 of 958
Topics in Java Programming
Q.321 Easy JDBC
Which interface in JDBC is used to execute a single SQL statement and return a ResultSet?
A Statement
B PreparedStatement
C CallableStatement
D Connection
Correct Answer:  A. Statement
EXPLANATION

Statement interface is used to execute simple SQL queries without parameters and return results as ResultSet.

Take Test
Q.322 Hard JDBC
In JDBC, what is the purpose of using a SavePoint in a transaction?
A To save the current connection state
B To create a checkpoint within a transaction that can be rolled back to independently
C To automatically commit pending changes
D To lock the database for exclusive access
Correct Answer:  B. To create a checkpoint within a transaction that can be rolled back to independently
EXPLANATION

A SavePoint allows you to roll back part of a transaction without rolling back the entire transaction. You can create nested transactions by setting multiple savepoints and rolling back to specific ones.

Take Test
Q.323 Medium JDBC
Which JDBC method allows you to retrieve column information such as column name, type, and size?
A ResultSetMetaData
B DatabaseMetaData
C ColumnMetaData
D TableMetaData
Correct Answer:  A. ResultSetMetaData
EXPLANATION

ResultSetMetaData interface provides information about the columns returned in a ResultSet, such as getColumnName(), getColumnType(), getColumnCount(), etc. Obtained via rs.getMetaData().

Take Test
Q.324 Hard JDBC
A batch update operation fails partially. How can you identify which statements failed in the batch?
A Check the exception message
B Use the int array returned by executeBatch() to check individual update counts
C Re-execute the batch statement by statement
D Use savepoints for each batch statement
Correct Answer:  B. Use the int array returned by executeBatch() to check individual update counts
EXPLANATION

executeBatch() returns an int array where each element represents the update count for the corresponding statement. A value of -3 (Statement.EXECUTE_FAILED) indicates failure for that statement.

Take Test
Q.325 Easy JDBC
What happens when you call rs.next() on a ResultSet after the last row?
A Returns true and loops back to the first row
B Returns false
C Throws a SQLException
D Remains on the last row
Correct Answer:  B. Returns false
EXPLANATION

The next() method returns false when there are no more rows available. It does not throw an exception or loop back; it simply indicates that there are no additional rows to traverse.

Take Test
Q.326 Hard JDBC
Which method is used to check if a CallableStatement has a return value from a stored procedure?
A hasResult()
B wasNull()
C getReturnValue()
D getObject(int parameterIndex)
Correct Answer:  B. wasNull()
EXPLANATION

The wasNull() method checks if the last value retrieved from a CallableStatement was NULL. To get the return value, you typically use getInt(), getString(), etc., and then check wasNull().

Take Test
Q.327 Hard JDBC
What is the default transaction isolation level in JDBC when autocommit is disabled?
A TRANSACTION_READ_UNCOMMITTED
B TRANSACTION_READ_COMMITTED
C TRANSACTION_REPEATABLE_READ
D Depends on the database driver
Correct Answer:  D. Depends on the database driver
EXPLANATION

The default isolation level depends on the specific database and JDBC driver configuration. Different databases have different defaults (MySQL is REPEATABLE_READ, Oracle is READ_COMMITTED).

Take Test
Q.328 Hard JDBC
A developer wants to prevent SQL injection attacks while executing dynamic queries. Which approach is most secure?
A Use String concatenation with input validation
B Use PreparedStatement with setString() methods
C Use regular expressions to filter input
D Use encrypted password fields in queries
Correct Answer:  B. Use PreparedStatement with setString() methods
EXPLANATION

PreparedStatement with parameterized queries is the most secure approach as it separates SQL logic from data. The database treats parameters as data, not executable code, preventing SQL injection.

Take Test
Q.329 Medium JDBC
In JDBC, which concurrency type allows modifications to the ResultSet?
A CONCUR_READ_ONLY
B CONCUR_UPDATABLE
C CONCUR_WRITE
D CONCUR_MODIFIABLE
Correct Answer:  B. CONCUR_UPDATABLE
EXPLANATION

CONCUR_UPDATABLE is the ResultSet concurrency type that allows the ResultSet to be updated. CONCUR_READ_ONLY prevents modifications.

Take Test
Q.330 Medium JDBC
Which JDBC feature allows multiple SQL statements to be sent to the database in a single round trip?
A Bulk operations
B Batch processing
C Transaction management
D Connection pooling
Correct Answer:  B. Batch processing
EXPLANATION

Batch processing allows multiple SQL statements to be grouped and sent together using addBatch() and executeBatch() methods, improving performance by reducing network overhead.

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