Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

958 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 331–340 of 958
Topics in Java Programming
Q.331 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.332 Medium JDBC
In JDBC, what does the ResultSet.absolute(5) method do?
A Moves cursor 5 positions forward
B Moves cursor to the 5th row
C Checks if row 5 exists
D Returns the absolute value at row 5
Correct Answer:  B. Moves cursor to the 5th row
EXPLANATION

The absolute(int row) method moves the cursor to the specified row number (1-based indexing). absolute(5) moves the cursor directly to row 5.

Take Test
Q.333 Medium JDBC
Which method is used to retrieve metadata about the database in JDBC?
A getMetaData()
B getDatabaseMetaData()
C getDBMetaData()
D fetchMetaData()
Correct Answer:  B. getDatabaseMetaData()
EXPLANATION

The getDatabaseMetaData() method is called on a Connection object to retrieve DatabaseMetaData information about the database, such as table names, column information, etc.

Take Test
Q.334 Medium JDBC
What is the correct way to use try-with-resources for JDBC operations?
A try(Connection con = DriverManager.getConnection(url)) { }
B try { Connection con = DriverManager.getConnection(url); }
C try-with-resources { Connection con = DriverManager.getConnection(url); }
D resource(Connection con = DriverManager.getConnection(url)) { }
Correct Answer:  A. try(Connection con = DriverManager.getConnection(url)) { }
EXPLANATION

The try-with-resources statement automatically closes resources implementing AutoCloseable. Since Connection implements AutoCloseable, it will be automatically closed.

Take Test
Q.335 Medium JDBC
Which exception is thrown when a database operation violates a unique constraint in JDBC?
A SQLException
B DataAccessException
C ConstraintViolationException
D SQLIntegrityConstraintViolationException
Correct Answer:  D. SQLIntegrityConstraintViolationException
EXPLANATION

SQLIntegrityConstraintViolationException is a specific subclass of SQLException that is thrown when integrity constraint violations occur, such as unique constraint violations.

Take Test
Q.336 Easy JDBC
In JDBC, what is the purpose of the Class.forName() method?
A To load and register the JDBC driver
B To establish a database connection
C To execute a SQL query
D To fetch data from ResultSet
Correct Answer:  A. To load and register the JDBC driver
EXPLANATION

Class.forName() is used to load the JDBC driver class dynamically and register it with the DriverManager. For example: Class.forName("com.mysql.cj.jdbc.Driver");

Take Test
Q.337 Medium JDBC
What does the PreparedStatement interface provide that Statement does not?
A Better error handling
B SQL injection prevention through parameterized queries
C Faster execution due to precompilation
D Both B and C
Correct Answer:  D. Both B and C
EXPLANATION

PreparedStatement provides both parameterized queries (preventing SQL injection) and precompilation of SQL statements, resulting in better security and performance compared to Statement.

Take Test
Q.338 Easy JDBC
Which interface represents a single row of data retrieved from a database in JDBC?
A Statement
B ResultSet
C Connection
D DatabaseMetaData
Correct Answer:  B. ResultSet
EXPLANATION

ResultSet interface represents the result set of a query. It contains the data returned from a database query and provides methods to access and traverse through the rows.

Take Test
Q.339 Easy JDBC
What is the correct syntax to retrieve an integer value from a ResultSet object at column index 2?
A rs.getInt(2);
B rs.getInteger(2);
C rs.fetchInt(2);
D rs.readInt(2);
Correct Answer:  A. rs.getInt(2);
EXPLANATION

The correct method is getInt(int columnIndex) which retrieves an integer value from the ResultSet at the specified column index (1-based indexing).

Take Test
Q.340 Easy JDBC
Which JDBC driver type is platform-independent and does not require native code installation?
A Type 1 Driver
B Type 2 Driver
C Type 3 Driver
D Type 4 Driver
Correct Answer:  D. Type 4 Driver
EXPLANATION

Type 4 drivers (thin drivers) are pure Java drivers that communicate directly with the database using the database native protocol. They are platform-independent and do not require native code.

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