Java Programming
Java OOP, collections, multithreading
212 Questions 10 Topics Take Test
Advertisement
Showing 71–80 of 212 questions
Q.71 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.72 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.73 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.74 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.75 Hard JDBC
What is the difference between update() and updateRow() methods in ResultSet?
A update() modifies a single column, updateRow() commits all column changes
B update() is for SELECT queries, updateRow() is for UPDATE queries
C update() is for integers, updateRow() is for all data types
D There is no difference; they are synonymous
Correct Answer:  A. update() modifies a single column, updateRow() commits all column changes
EXPLANATION

update*() methods (like updateInt(), updateString()) modify individual column values in the current row, while updateRow() commits all these changes to the database.

Take Test
Q.76 Hard JDBC
In JDBC, what does the ResultSet.TYPE_SCROLL_INSENSITIVE constant represent?
A Non-scrollable result set
B Scrollable result set that doesn't reflect database changes
C Forward-only result set
D Bidirectional result set
Correct Answer:  B. Scrollable result set that doesn't reflect database changes
EXPLANATION

TYPE_SCROLL_INSENSITIVE creates scrollable ResultSet (can move forward/backward) but changes made to database after ResultSet creation are not reflected.

Take Test
Q.77 Hard JDBC
Which JDBC feature allows you to call stored procedures?
A Statement
B PreparedStatement
C CallableStatement
D ExecutableStatement
Correct Answer:  C. CallableStatement
EXPLANATION

CallableStatement is used to invoke stored procedures and functions. It extends PreparedStatement and supports IN, OUT, and INOUT parameters.

Take Test
Q.78 Hard JDBC
What is the difference between execute(), executeQuery(), and executeUpdate()?
A execute() returns boolean, executeQuery() returns ResultSet, executeUpdate() returns int
B All three are identical
C execute() is fastest, others are slower
D executeQuery() updates database, executeUpdate() retrieves data
Correct Answer:  A. execute() returns boolean, executeQuery() returns ResultSet, executeUpdate() returns int
EXPLANATION

execute() returns boolean (true if ResultSet available), executeQuery() returns ResultSet for SELECT, executeUpdate() returns row count for INSERT/UPDATE/DELETE.

Take Test
Q.79 Hard JDBC
How would you implement batch processing in JDBC for multiple INSERT operations?
A Use addBatch() and executeBatch() methods
B Execute each insert in a loop separately
C Use multiple connections
D Create multiple statements
Correct Answer:  A. Use addBatch() and executeBatch() methods
EXPLANATION

addBatch() adds SQL command to batch, executeBatch() executes all batched commands at once, improving performance significantly for multiple operations.

Take Test
Q.80 Hard JDBC
Consider code: String query = "SELECT * FROM users WHERE id=" + userId; stmt.executeQuery(query); What security issue exists?
A Performance degradation
B SQL Injection vulnerability
C Memory leak
D Connection timeout
Correct Answer:  B. SQL Injection vulnerability
EXPLANATION

This is vulnerable to SQL injection as user input is directly concatenated. Using PreparedStatement with parameters prevents this: "SELECT * FROM users WHERE id=?"

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