What is true of the following if the music database exists and contains a songs table with one row when run using a JDBC 4.0 driver? (Choose two.)
import java.sql.*; public class Main { public static void main(String[] args) throws Exception { String url = "jdbc:derby:music"; Connection conn = DriverManager.getConnection(url); Statement stmt = conn.createStatement(); stmt.execute("update songs set name = 'The New Song'"); } }
execute()
rather than executeUpdate()
.execute()
method returns a boolean.execute()
method returns an int.D, E.
While this code does not close the Statement and Connection, it does compile, making Option A incorrect.
Java defaults to auto-commit, which means the update happens right away, making Option C incorrect.
Option B is incorrect because either execute()
or executeUpdate()
is allowed for UPDATE SQL.
The difference is the return type.
The execute()
method returns a boolean while the executeUpdate()
method returns an int.
The code also runs without error, making Options D and E the answer.
And remember to always close your resources in real code to avoid a resource leak.