What does the DriverManager.getConnection() method return?
Answer: B
DriverManager.getConnection() establishes a connection to the database and returns a Connection object.
Q.182Easy
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.183Easy
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.184Easy
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.185Easy
Which JDBC API is used to execute parameterized queries safely?
Answer: B
PreparedStatement allows parameterized queries using placeholders (?) and prevents SQL injection attacks.
Advertisement
Q.186Easy
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.187Easy
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.
Q.188Easy
What exception is thrown when a database connection fails in JDBC?
Answer: B
SQLException is thrown when database-related errors occur, including connection failures and SQL execution errors.
Q.189Easy
In JDBC, what does the executeQuery() method return?
Answer: C
executeQuery() returns a ResultSet containing the rows fetched from the database for SELECT queries.
Q.190Easy
Which interface in JDBC is used to execute parameterized queries and prevent SQL injection attacks?
Answer: B
PreparedStatement is used for parameterized queries with placeholders (?), which prevents SQL injection by separating SQL logic from data.
Q.191Easy
What is the correct sequence to establish a JDBC connection in Java?
Answer: A
The correct JDBC connection sequence is: Class.forName() → DriverManager.getConnection() → Create Statement → Execute Query → Close resources.
Q.192Easy
Which method of Connection interface is used to start a transaction in JDBC?
Answer: A
setAutoCommit(false) disables auto-commit mode, allowing manual control over transactions through commit() and rollback() methods.
Q.193Easy
In JDBC, what does the BatchUpdate feature allow developers to do?
Answer: B
addBatch() and executeBatch() methods allow multiple SQL statements to be grouped and executed together, reducing network traffic and improving performance.
Q.194Easy
Which exception is thrown when a JDBC driver is not found in the classpath?
Answer: B
When Class.forName() cannot locate the driver class, it throws ClassNotFoundException, indicating the driver JAR is not in the classpath.
Q.195Easy
What is the difference between commit() and rollback() in JDBC transactions?
Answer: A
commit() permanently saves all changes made during the transaction, while rollback() discards all changes and reverts to the previous state.
Q.196Easy
In a JDBC application, which interface is responsible for executing SQL queries and returning ResultSet objects?
Answer: A
The Statement interface is used to execute SQL queries. Connection creates the statement, Driver manages connections, and DataSource provides connection pooling, but Statement is the actual executor.
Q.197Easy
What is the primary purpose of Generics in Java?
Answer: A
Generics enable type safety at compile time and eliminate the need for explicit type casting, reducing runtime errors.
Q.198Easy
Which keyword is used to declare a generic class in Java?
Answer: A
<T> is the standard syntax for declaring a generic type parameter in Java classes.
Q.199Easy
What will be the output of the following code?
List<String> list = new ArrayList<>();
list.add("Java");
System.out.println(list.get(0).length());
Answer: A
"Java" has 4 characters. The generic type ensures the element is a String, so .length() method is available without casting.
Q.200Easy
Which of the following is a valid generic method declaration?
Answer: A
The correct syntax for a generic method is: access_modifier <T> returnType methodName(T parameter). The type parameter <T> must come before the return type.