Which action can be used to load a database driver by using JDBC3.0?
A.
Add the driver class to the META-INF/services folder of the JAR file.
B.
Include the JDBC driver class in a jdbc.properties file.
C.
Use the java.lang.Class.forName method to load the driver class.
D.
Use the DriverManager.getDriver method to load the driver class.
C.
Use the java.lang.Class.forName method to load the driver class.
C
C is correct
String databaseURL = “jdbc:mysql://localhost:3306/test”;
String user = “user”;
String password = “password”;
Connection conn = null;
try {
Class.forName(“com.mysql.jdbc.Driver”); –> c
conn = DriverManager.getConnection(databaseURL, user, password);
if (conn != null) {
System.out.println(“Connected to the database”);
}
} catch (ClassNotFoundException ex) {
System.out.println(“Could not find database driver class”);
ex.printStackTrace();
} catch (SQLException ex) {
System.out.println(“An error occurred. Maybe user/password is invalid”);
ex.printStackTrace();
}
C