At the command prompt, enter notepad ChkLoadJdbc.java to open Notepad
Open the Java project folder (ChkLoadJdbc) you have already created Right click on the src folder New-> Select Class The New Java Class screen is displayed
Name: ChkLoadJdbc □ Check "public static void main (String [] args)" □ Check "Generate comment" Press the "Finish" button
public class ChkLoadJdbc {
public static void main(String[] args) throws InstantiationException, IllegalAccessException {
String msg = "";
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
msg = "The driver was successfully loaded";
} catch (ClassNotFoundException e){
msg = "Failed to load the driver";
}
System.out.println(msg);
}
}
Run after programming
If you have successfully called the JDBC driver, "Successfully loaded the driver" If it fails, "Failed to load driver" is displayed.
In case of failure, check if the CLASSPATH setting is correct and correct.
Java-database connection / Java-MySQL connection ① Overview of JDBC and JDBC driver (2) JDBC driver acquisition method (for MySQL) and data connection preparation ③-1 How to set CLASSPATH in environment variable ③-2 How to set CLASSPATH to Eclipse build bus ④ Load JDBC driver ⑤ Connect to database (MySQL) to search table information and display search results
Recommended Posts