Home Subjects Java Programming JDBC

Java Programming
JDBC

Java OOP, collections, multithreading

29 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 21–29 of 29
Topics in Java Programming
Q.21 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");

Test
Q.22 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.

Test
Q.23 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).

Test
Q.24 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.

Test
Q.25 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.

Test
Q.26 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.

Test
Q.27 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.

Test
Q.28 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.

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

Statement interface is used to execute SQL queries. Connection is used to establish database connection, ResultSet holds query results, and Driver manages database connections.

Test
IGET
IGET AI
Online · Exam prep assistant
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