Parts (jar files) that are not included in the standard system library are called "external libraries". The JDBC driver is one of the external libraries. In order to use an external library in addition to the standard system library, it is necessary to make settings to tell the compiler and JVM (JavaVirtualMachine: Java virtual environment) the location of this external library. This setting is called "CLASSPATH setting".
There are several ways to set the CLASSPATH, In this Qiita personal memo,
Copy mysql-connector-java-x.x.xx-bin.jar Open Windows Explorer (Windows button + E button) Open C: \ Program Files \ Java \ jdk x.x.x_xxx \ lib
Paste the mysql-connector-java-x.x.xx-bin.jar you copied earlier After pasting, you can close Windows Explorer
Then click the Windows button-> right-click on your computer-> select Properties Click the advanced system settings link Press the environment variable button
If the variable CLASSPATH does not exist in the "System environment variables" list, register as follows.
Press the new button under "System Variables". Variable name: CLASSPATH Variable value:.; C: \ Program Files \ Java \ jdk x.x.x_xxx \ lib \ mysql-connector-java-x.x.xx-bin.jar;
If the variable CLASSPATH exists in the "System environment variables" list, register it as follows.
Select the column where the CLASSPATH is displayed Press the edit button under "System Variables"
Variable name: CLASSPATH Variable value:.; Xxxxxxxxxxxxx.jar; C: \ ProgramFiles \ Java \ jdkx.x.x_xxx \ lib \ mysql-connector-java-x.x.xx-bin.jar; Add in the format.
If this doesn't work, set it from Eclipse of your memo next time (low voice)
☆ Variable value:.; C: \ Program Files \ Java \ jdk x.x.x_xxx \ lib \ mysql-connector-java-x.x.xx-bin.jar; Variable values are declared separated by a; (semicolon) symbol.
The first. (Dot) means the Java program (the program you are about to create) that connects to the JDBC driver. Also, C: \ Program Files \ Java \ jdk x.x.x_xxx \ lib \ mysql-connector-java-x.x.xx-bin.jar shows the filename and location of the external library that will be the JDBC driver.
If you write an instruction to call the JDBC driver manager in the Java program created after this, the JDBC driver will call the specified JDBC driver further and try to connect to the target database.
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