Java Connection MySQL Database

Source: Internet
Author: User

One months ago, there were a lot of problems when I did the work, and we solved them all. After it is done, it is time to re-do the work on another computer, or to meet some of the same problems, and solve them. Fortunately the time is not long, vaguely remember how to solve. Good memory is better than bad writing, or write down, in case you encounter similar work to do later.

Next I will write in the form of a point, so easy to read a little.

1, install Java, Eclipse, Mysql, how to install the Internet has, do not repeat.

2, download Java connection MySQL jar package, I am from the official website Mysql-connector-java-5.1.45-bin.jar, but need to log in, other places also have can download.

3, import the jar package, first select the appropriate project, then click the menu bar Project->properties->java Bulid path->libraries->add External JARs, Find the jar package you downloaded, select it, click Apply and close on the right.

4. Load Driver

There are two methods, one of which is import

Import com.mysql.jdbc.Connection;

The other is to call the Class.forName () method in the function to load the driver

Class.forName ("com.mysql.jdbc.Driver");

5. Establish the connection

Java Connection MySQL Database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.