Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 146

Given the code fragment:

Assume that dbURL, userName, and password are valid.

Which code fragment can be inserted at line n1 to enable the code to print Connection Established?

    Correct Answer: A

    To print 'Connection Established.', the code should establish a connection to the database. The proper way to do this is by using the DriverManager.getConnection method with the appropriate parameters. Option A correctly uses a Properties object to store the username and password, and then calls DriverManager.getConnection with the database URL and the Properties object. This method call is consistent with the standard usage of DriverManager.getConnection(String url, Properties info), where 'url' is the database URL and 'info' is a list of connection arguments, including at least the 'user' and 'password' properties.

Discussion
steefaandOption: A

A is correct.

AVB22Option: A

A is the answer, public static Connection getConnection(String url, Properties info) Parameters: url - a database url of the form jdbc:subprotocol:subname info - a list of arbitrary string tag/value pairs as connection arguments; normally at least a "user" and "password" property should be included