Which action can be used to load a database driver by u…

Which action can be used to load a database driver by using JDBC3.0?

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.



Leave a Reply 4

Your email address will not be published. Required fields are marked *


smh

smh

C.
Use the java.lang.Class.forName method to load the driver class.

Berti John

Berti John

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();
}