Connecting to MySQL database through JDBC in eclipse
Recommended related mysql video tutorials: "mysql tutorial"
1. First, download Connector/J from the MySQL official website. Connector/J is a jar package used to connect to MySQL. The downloaded compressed package needs to be decompressed locally and decompressed. The final file is as shown in the figure
##2. Download For the version of Connector/J, please refer to the figure below
3. Add the driver jar that connects to the database in the new eclipse project package, right-click on the newly created project and click Add External
##4. Select to extract to the local Connector/ jar package in the J file
5. Then enter the following code in the new project
6. Class.forName("com.mysql.cj.jdbc.Driver"); in the code is used to register the driver that connects to MySQL , the above code is not suitable for all databases, because the driver of each data is different. DriverManager.getConnection(URL,USER_NAME,PASSWORD); used to connect to the database
7. Running the code output If the MYSQL driver is successfully loaded, the database connection is successful
Note
It is easy to report errors when using the official URL, you need to use the # provided in the above code
##mydb in the URL is your own database name
The above is the detailed content of How to connect mysql database through jdbc in eclipse. For more information, please follow other related articles on the PHP Chinese website!