Home Subjects Java Programming JDBC

Java Programming
JDBC

Java OOP, collections, multithreading

100 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 61–70 of 100
Topics in Java Programming
Q.61 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.62 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
Q.63 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.64 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.65 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.66 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.67 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.68 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.69 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.70 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
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