Home > Database > Mysql Tutorial > How to connect mysql database through jdbc in eclipse

How to connect mysql database through jdbc in eclipse

黄舟
Release: 2019-02-27 14:55:49
Original
5575 people have browsed it

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

How to connect mysql database through jdbc in eclipse


##2. Download For the version of Connector/J, please refer to the figure below

How to connect mysql database through jdbc in eclipse

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

How to connect mysql database through jdbc in eclipse

##4. Select to extract to the local Connector/ jar package in the J file

How to connect mysql database through jdbc in eclipse

5. Then enter the following code in the new project

How to connect mysql database through jdbc in eclipse

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

How to connect mysql database through jdbc in eclipse

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template