Which interface in JDBC is used to execute SQL queries and obtain results?
Answer: A
Statement interface is used to execute SQL queries. Connection is used to establish database connection, ResultSet holds query results, and Driver manages database connections.
Q.2Easy
What is the correct order of JDBC operations?
Answer: A
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.
Q.3Easy
Which JDBC driver type is platform-independent and does not require native code?
Answer: D
Type 4 (Thin) drivers are pure Java drivers, platform-independent, and don't require native code. They communicate directly with database using Java sockets.
Q.4Easy
What exception is thrown when a database connection cannot be established?
Answer: A
SQLException is thrown for database-related errors including connection failures. ClassNotFoundException occurs when JDBC driver class is not found.
Q.5Easy
Which method is used to retrieve a String value from a ResultSet object?
Answer: B
getString() method retrieves String values from ResultSet. getInt() gets integer values, and fetchString/readString are not valid JDBC methods.
Advertisement
Q.6Easy
Which JDBC driver type is platform-independent and does not require native code installation?
Answer: D
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.
Q.7Easy
What is the correct syntax to retrieve an integer value from a ResultSet object at column index 2?
Answer: A
The correct method is getInt(int columnIndex) which retrieves an integer value from the ResultSet at the specified column index (1-based indexing).
Q.8Easy
Which interface represents a single row of data retrieved from a database in JDBC?
Answer: B
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.
Q.9Easy
In JDBC, what is the purpose of the Class.forName() method?
Answer: A
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");
Q.10Easy
What happens when you call rs.next() on a ResultSet after the last row?
Answer: B
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.
Q.11Easy
Which interface in JDBC is used to execute a single SQL statement and return a ResultSet?
Answer: A
Statement interface is used to execute simple SQL queries without parameters and return results as ResultSet.
Q.12Easy
What is the primary advantage of using PreparedStatement over Statement in JDBC?
Answer: A
PreparedStatement pre-compiles SQL and uses parameterized queries, preventing SQL injection and improving performance.
Q.13Easy
Which JDBC method is used to retrieve the number of rows affected by an INSERT, UPDATE, or DELETE statement?
Answer: B
executeUpdate() returns an int representing the number of rows affected by the SQL statement execution.
Q.14Easy
What does the DriverManager.getConnection() method return?
Answer: B
DriverManager.getConnection() establishes a connection to the database and returns a Connection object.
Q.15Easy
In JDBC, which exception is thrown when the database driver class is not found?
Answer: B
ClassNotFoundException is thrown when Class.forName() cannot locate the JDBC driver class.
Q.16Easy
What is the purpose of the Connection.commit() method in JDBC?
Answer: B
commit() finalizes the transaction and persists all changes made since the last commit or rollback.
Q.17Easy
Which interface in JDBC is used to execute SQL queries and retrieve results?
Answer: A
Statement interface is used to execute SQL queries. Connection creates statements, ResultSet holds results, and Driver manages connections.
Q.18Easy
Which JDBC API is used to execute parameterized queries safely?
Answer: B
PreparedStatement allows parameterized queries using placeholders (?) and prevents SQL injection attacks.
Q.19Easy
What is the correct syntax to load a JDBC driver in Java?
Answer: B
Class.forName() is the standard way to load JDBC drivers. It dynamically loads the driver class.
Q.20Easy
Which method is used to retrieve the next row from a ResultSet?
Answer: B
The next() method moves the cursor to the next row in the ResultSet and returns true if a row exists.