JDBC Flashcards
7 cards from real 1Z0-819 practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 JDBC flashcards as text
Which `ResultSet` getter retrieves a column value by its 1-based column index as a `String`?
Answer: getString(1)
JDBC ResultSet column indices are 1-based, so `getString(1)` retrieves the first column as a String.
What is the correct JDBC URL format for connecting to a local MySQL database named `testdb` on the default port?
Answer: jdbc:mysql://localhost:3306/testdb
A standard JDBC URL follows the pattern `jdbc:://:/`, so `jdbc:mysql://localhost:3306/testdb` is correct.
Which method closes a `ResultSet`, `Statement`, and `Connection` together when used in a try-with-resources block?
Answer: Each implements AutoCloseable so all are closed automatically by try-with-resources
`Connection`, `Statement`, and `ResultSet` all implement `AutoCloseable`, so they are automatically closed at the end of a try-with-resources block.
What does `Statement.executeBatch()` return?
Answer: An int[] where each element is the update count for the corresponding command
`executeBatch()` returns an `int[]` array where each element represents the update count for the corresponding SQL command added via `addBatch()`.
Which `ResultSet` constant specifies that the cursor can scroll both forward and backward and is insensitive to database changes?
Answer: ResultSet.TYPE_SCROLL_INSENSITIVE
`ResultSet.TYPE_SCROLL_INSENSITIVE` allows bidirectional scrolling but does not reflect changes made to the database after the ResultSet was opened.
Which `Connection` method creates a `Statement` object for executing static SQL?
Answer: connection.createStatement()
`Connection.createStatement()` creates a `Statement` object used to execute static SQL queries without parameters.
When using `PreparedStatement`, which method binds a Java `int` value to the first placeholder?
Answer: setInt(1, value)
`PreparedStatement.setInt(1, value)` binds an int to the first `?` placeholder; parameters are 1-indexed and the method is `setInt`, not `setInteger`.