Summary of operations on connecting Eclipse To My SQL database, eclipsesql

Source: Internet
Author: User

Summary of operations on connecting Eclipse To My SQL database, eclipsesql

How to connect Eclipse To My SQL database

(Test by yourself and start to learn how to connect to the database by connecting to Eclipse (my Eclipse version is 4.5.2, And the jar package version of The Jdbc driver is 5.1.7, I have a lot of experience on the Internet, but I have found many errors on the Internet. I hope this blog will help you)

1: First you need to download the Jdbc drive (mysql-connector-java-5.1.7-bin.jar) This file (Baidu cloud disk,password c22r)

It is also difficult to download the file above, so I would like to share it for your convenience.

2: After downloading the preceding Jdbc drive, you can start to operate it. First, open Eclipse and create a Project. My Project name is demo. Then, right-click src, find new, find Floder, and

Right-click src under the project and paste the downloaded Jdbc drive to the lib under the demo project. Then, click the jar package you just pasted, find the build path and continue to find the add to build path. The result is shown in. After the add is complete, you can use Eclipse to connect to My SQL database.

The code for connecting to the database is as follows (note Connection connect = DriverManage. getConnection ("jdbc: mysql: // localhost: 3306/test", "root", "password "))

The "password" in the above sentence is your database's own password. You need to modify it yourself. The above "jdbc: mysql: // localhost: the test in 3306/test is a table created by myself using mysql, which is created by myself and requires extra attention. (The create my SQL statement will be found elsewhere in this blog, please note)

Package com. ningmengxueyuan;

Import java. SQL .*;

Public class MysqlJdbc {

Public static void main (String args []) {
Try {
Class. forName ("com. mysql. jdbc. Driver"); // load the mysql jdbc Driver
// Class. forName ("org. gjt. mm. mysql. Driver ");
System. out. println ("Success loading Mysql Driver! ");
} Catch (Exception e ){
System. out. print ("Error loading Mysql Driver! ");
E. printStackTrace ();
Try {
Connection connect = DriverManager. getConnection (
"Jdbc: mysql: // localhost: 3306/test1", "root", "123456 ");
// The Connection URL is jdbc: mysql // server address/database name, followed by the login user name and password

System. out. println ("Success connect Mysql server! ");
Statement stmt = connect. createStatement ();
ResultSet rs = stmt.exe cuteQuery ("select * from user ");
// User: name of your table
While (rs. next ()){
System. out. println (rs. getString ("name "));
} Catch (Exception e ){
System. out. print ("get data error! ");
E. printStackTrace ();



Related Article

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: 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.