Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

270 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 91–100 of 270
Topics in Java Programming
Q.91 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.92 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.93 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.94 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.95 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.96 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
Q.97 Easy JDBC
Which method is used to retrieve a String value from a ResultSet object?
A getInt()
B getString()
C fetchString()
D readString()
Correct Answer:  B. getString()
EXPLANATION

getString() method retrieves String values from ResultSet. getInt() gets integer values, and fetchString/readString are not valid JDBC methods.

Take Test
Q.98 Easy JDBC
What exception is thrown when a database connection cannot be established?
A SQLException
B ClassNotFoundException
C IOExceptionn
D NullPointerException
Correct Answer:  A. SQLException
EXPLANATION

SQLException is thrown for database-related errors including connection failures. ClassNotFoundException occurs when JDBC driver class is not found.

Take Test
Q.99 Easy JDBC
Which JDBC driver type is platform-independent and does not require native code?
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 (Thin) drivers are pure Java drivers, platform-independent, and don't require native code. They communicate directly with database using Java sockets.

Take Test
Q.100 Easy JDBC
What is the correct order of JDBC operations?
A Load Driver → Create Connection → Create Statement → Execute Query → Close Resources
B Create Connection → Load Driver → Execute Query → Create Statement → Close Resources
C Load Driver → Execute Query → Create Connection → Create Statement → Close Resources
D Create Statement → Load Driver → Create Connection → Execute Query → Close Resources
Correct Answer:  A. Load Driver → Create Connection → Create Statement → Execute Query → Close Resources
EXPLANATION

The correct JDBC sequence is: 1) Load the JDBC driver, 2) Create connection, 3) Create statement, 4) Execute query, 5) Process results, 6) Close resources.

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