Last Updated: December 6, 2025
31 quizzes
Obtain a JDBC connection using DriverManager so that you can perform database operations.
Connection connection = DriverManager.(url, user, password);Click an option to fill the blank:
Prepare a reusable SQL query with a parameter placeholder to safely filter by username.
PreparedStatement ps = connection.("SELECT * FROM users WHERE username = ?");Click an option to fill the blank:
Start managing multiple JDBC operations as a single transaction instead of auto-committing each statement.
connection.(false);Click an option to fill the blank:
Which JDBC component is responsible for managing available database drivers and establishing connections?
Which JDBC driver type communicates directly with the database using a native protocol and requires no native libraries?
In a typical JDBC URL like "jdbc:mysql://localhost:3306/mydb", what does "mysql" represent?
Which method on Statement is typically used to execute an INSERT, UPDATE, or DELETE statement?
What is a key advantage of using PreparedStatement over Statement?
Which interface is specifically designed for calling stored procedures in JDBC?
Which ResultSet type allows moving both forward and backward but does NOT see changes committed after it was created?
Which property of transactions ensures that either all operations complete successfully or none are applied?
In JDBC, what happens immediately after calling connection.commit() when auto-commit is disabled?
What is a primary purpose of a JDBC connection pool in a web application?
Which method on ResultSet moves the cursor to the next row?
Order the steps to execute a SELECT query using a simple Statement and process the results.
Drag and drop to reorder, or use the arrows.
Arrange the steps to perform a manual JDBC transaction that transfers money between two accounts.
Drag and drop to reorder, or use the arrows.
What is the output of this JDBC-related code that reads from a ResultSet?
1int count = 0;
2if (rs.next()) {
3 count = rs.getInt("user_count");
4}
5System.out.println("Users=" + count);Assume rowsUpdated is the return value of executeUpdate. What is the output?
1int rowsUpdated = 3;
2System.out.println("Updated:" + rowsUpdated);Predict the output when printing auto-commit mode before starting an explicit transaction.
1Connection conn = null; // assume a valid connection
2boolean auto = conn.getAutoCommit();
3System.out.println(auto);What is printed after configuring a read-only ResultSet concurrency mode?
1int type = ResultSet.TYPE_SCROLL_INSENSITIVE;
2int concur = ResultSet.CONCUR_READ_ONLY;
3System.out.println(concur == ResultSet.CONCUR_READ_ONLY);Assume poolSize is the initial number of connections created in a connection pool. What is the output?
1int initialConnections = 5;
2int borrowed = 2;
3int available = initialConnections - borrowed;
4System.out.println("Available=" + available);This code is intended to execute a parameterized SELECT using PreparedStatement. Identify and fix the bug.
Click on the line(s) that contain the bug.
String sql = "SELECT * FROM users WHERE id = ?";PreparedStatement ps = connection.prepareStatement(sql);ps.setString(1, 10);ResultSet rs = ps.executeQuery();This code is meant to run two updates in a single transaction. Find and correct the transaction management bug.
Click on the line(s) that contain the bug.
Connection conn = DriverManager.getConnection(url, user, pass);conn.setAutoCommit(true);PreparedStatement debit = conn.prepareStatement("UPDATE accounts SET balance = balance - ? WHERE id = ?");PreparedStatement credit = conn.prepareStatement("UPDATE accounts SET balance = balance + ? WHERE id = ?");// set parameters heredebit.executeUpdate();credit.executeUpdate();conn.commit();Match each JDBC interface with what it primarily represents.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each transaction or pooling concept to its role.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Complete the code to create a scroll-insensitive, read-only ResultSet using a Statement.
Statement stmt = connection.createStatement(, );ResultSet rs = stmt.executeQuery("SELECT * FROM employees");Click an option to fill blank 1:
Complete the code to configure and execute a stored procedure with one IN parameter and one OUT parameter.
CallableStatement cs = connection.prepareCall("{call get_user_name(?, ?)}");cs.setInt(1, 42);cs.(2, java.sql.Types.VARCHAR);cs.();String name = cs.getString(2);Click an option to fill blank 1:
Complete the code to safely close JDBC resources using try-with-resources around a query.
try (Connection conn = DriverManager.getConnection(url, user, pass); PreparedStatement ps = conn.("SELECT id FROM users"); ResultSet rs = ps.()) { if (rs.next()) { System.out.println(rs.getInt(1)); }}Click an option to fill blank 1:
Complete the code to borrow and return a Connection from a simple connection pool.
ConnectionPool pool = new ConnectionPool(5);Connection conn = pool.();// perform JDBC work herepool.(conn);Click an option to fill blank 1:
Click the line that will most likely cause a SQLException related to using Statement with user input.
Click on the line to select.
String userInput = "alice";Statement stmt = connection.createStatement();String sql = "SELECT * FROM users WHERE username = '" + userInput + "'";ResultSet rs = stmt.executeQuery(sql);Click the line that most directly enables manual transaction control in this code.
Click on the line to select.
Connection conn = DriverManager.getConnection(url, user, pass);conn.setAutoCommit(false);PreparedStatement ps = conn.prepareStatement("UPDATE products SET stock = stock - ? WHERE id = ?");// execute updates and commit/rollback later