Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

958 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 291–300 of 958
Topics in Java Programming
Q.291 Medium JDBC
What is the difference between execute() and executeUpdate() methods?
A execute() returns boolean, executeUpdate() returns int
B execute() can execute any SQL statement, executeUpdate() only for DML
C Both A and B are correct
D There is no difference
Correct Answer:  C. Both A and B are correct
EXPLANATION

execute() returns true/false and handles any SQL, while executeUpdate() returns affected rows count for DML statements only.

Take Test
Q.292 Medium JDBC
In JDBC, which class is used to retrieve database metadata information?
A ResultSet
B Statement
C DatabaseMetaData
D Connection
Correct Answer:  C. DatabaseMetaData
EXPLANATION

DatabaseMetaData provides information about the database, tables, columns, and other database properties.

Take Test
Q.293 Medium JDBC
What does ResultSetMetaData.getColumnCount() return?
A Number of rows in ResultSet
B Number of columns in ResultSet
C Column data type
D Column name
Correct Answer:  B. Number of columns in ResultSet
EXPLANATION

getColumnCount() returns the total number of columns present in the ResultSet.

Take Test
Q.294 Medium JDBC
What is the benefit of using PreparedStatement over Statement for repeated queries?
A Faster execution due to pre-compilation
B Automatic SQL injection prevention
C Better readability of code
D Both A and B
Correct Answer:  D. Both A and B
EXPLANATION

PreparedStatement offers both pre-compilation for performance and SQL injection prevention through parameterized queries.

Take Test
Q.295 Medium JDBC
Which JDBC method executes UPDATE, INSERT, or DELETE statements?
A executeQuery()
B execute()
C executeUpdate()
D executeBatch()
Correct Answer:  C. executeUpdate()
EXPLANATION

executeUpdate() executes DML statements and returns the number of rows affected.

Take Test
Q.296 Medium JDBC
What is the purpose of Connection.commit() in JDBC?
A Close the connection
B Save all changes made in the current transaction
C Rollback transactions
D Create a new statement
Correct Answer:  B. Save all changes made in the current transaction
EXPLANATION

commit() saves all changes made during the current transaction permanently to the database.

Take Test
Q.297 Easy JDBC
In JDBC, what does the executeQuery() method return?
A int
B boolean
C ResultSet
D void
Correct Answer:  C. ResultSet
EXPLANATION

executeQuery() returns a ResultSet containing the rows fetched from the database for SELECT queries.

Take Test
Q.298 Easy JDBC
What exception is thrown when a database connection fails in JDBC?
A IOException
B SQLException
C ClassNotFoundException
D NullPointerException
Correct Answer:  B. SQLException
EXPLANATION

SQLException is thrown when database-related errors occur, including connection failures and SQL execution errors.

Take Test
Q.299 Easy JDBC
Which method is used to retrieve the next row from a ResultSet?
A getNext()
B next()
C moveToNext()
D fetchNext()
Correct Answer:  B. next()
EXPLANATION

The next() method moves the cursor to the next row in the ResultSet and returns true if a row exists.

Take Test
Q.300 Easy JDBC
What is the correct syntax to load a JDBC driver in Java?
A DriverManager.loadDriver('com.mysql.jdbc.Driver');
B Class.forName('com.mysql.jdbc.Driver');
C Driver.load('com.mysql.jdbc.Driver');
D Connection.loadDriver('com.mysql.jdbc.Driver');
Correct Answer:  B. Class.forName('com.mysql.jdbc.Driver');
EXPLANATION

Class.forName() is the standard way to load JDBC drivers. It dynamically loads the driver class.

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