chapter 15 - JDBC Flashcards
Which interface can be used to execute a stored procedure on the database?
The CallableStatement interface in Java is used to execute stored procedures on a database. It is part of the java.sql package and allows calling both stored procedures and functions.
JDBC stands for Java Database Connectivity and is used to connect Java applications to databases.
true
In JDBC, the Connection interface is used to send SQL statements to the database.
False (The Statement interface is used to send SQL statements, while Connection is used to establish a database connection.)
The DriverManager class is responsible for loading database drivers and establishing connections.
True
The ResultSet interface in JDBC is used to update the structure of the database tables.
False (ResultSet is used to retrieve and navigate query results, not update table structure.)
JDBC in Java 17 supports try-with-resources to automatically close resources such as Connection, Statement, and ResultSet.
True.
What does the execute() method of PreparedStatement do?
It executes the SQL statement and returns true if the result is a ResultSet, or false if the result is an update count or no result.
When should you use execute() instead of executeQuery() or executeUpdate()?
Use execute() when the SQL could return either a ResultSet or an update count — such as dynamic SQL or stored procedures.
After calling execute(), how do you access the result?
Use getResultSet() to access a ResultSet, or getUpdateCount() for the number of affected rows. Use getMoreResults() for additional results.