Given this code snippet:
public static Connection connectToDb() throws SQLException { String url = "jdbc:mysql://localhost:3306/"; String database = "addressBook"; String userName = "root"; String password = "mysql123"; // CONNECT_TO_DB }
Which one of the following statements will you replace with the comment CONNECT_TO_DB to create a Connection object?
a)return DatabaseManager.getConnection(url, database, userName, password); b)return Connection.getConnection(url, database, userName, password); c)return DriverManager.getConnection(url + database, userName, password); d)return DatabaseDriver.getConnection(url + database, userName, password);
c)
the getConnection()
method in DriverManager takes three String arguments and returns a Connection:.
Connection getConnection(String url, String user, String password)
hence, option c) is the correct answer.
the other three options will result in compiler errors.