Java Programming
Java OOP, collections, multithreading
270 Questions 10 Topics Take Test
Advertisement
Showing 81–90 of 270 questions
Q.81 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.82 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.83 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
Q.84 Easy JDBC
Which JDBC API is used to execute parameterized queries safely?
A Statement
B PreparedStatement
C ResultSet
D MetaData
Correct Answer:  B. PreparedStatement
EXPLANATION

PreparedStatement allows parameterized queries using placeholders (?) and prevents SQL injection attacks.

Take Test
Q.85 Easy JDBC
Which interface in JDBC is used to execute SQL queries and retrieve results?
A Statement
B Connection
C ResultSet
D Driver
Correct Answer:  A. Statement
EXPLANATION

Statement interface is used to execute SQL queries. Connection creates statements, ResultSet holds results, and Driver manages connections.

Take Test
Q.86 Easy JDBC
What is the purpose of the Connection.commit() method in JDBC?
A To establish a new database connection
B To permanently save all changes made in the current transaction
C To execute the next SQL statement
D To close the database connection
Correct Answer:  B. To permanently save all changes made in the current transaction
EXPLANATION

commit() finalizes the transaction and persists all changes made since the last commit or rollback.

Take Test
Q.87 Easy JDBC
In JDBC, which exception is thrown when the database driver class is not found?
A SQLException
B ClassNotFoundException
C DriverNotFoundException
D DatabaseException
Correct Answer:  B. ClassNotFoundException
EXPLANATION

ClassNotFoundException is thrown when Class.forName() cannot locate the JDBC driver class.

Take Test
Q.88 Easy JDBC
What does the DriverManager.getConnection() method return?
A A Statement object
B A Connection object
C A ResultSet object
D A DatabaseMetaData object
Correct Answer:  B. A Connection object
EXPLANATION

DriverManager.getConnection() establishes a connection to the database and returns a Connection object.

Take Test
Q.89 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.90 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
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