Download database connection driver on official website http://www.mysql.com/downloads/
This article uses a driver version of mysql-connector-java-5.1.40
First, create a Java test Project Mysqlconnectorstest
Under Project, wear a Lib folder to hold the MySQL driver package.
Right-click Drive Package build path to add operation, open referenced library under the new Mysql-connector-java-5.1.40-bin.jar
Double-clicking will see a lot of connection packs.
Add driver package successfully!
Second, the test
New Class CC under SRC.
PackageRR;ImportJava.sql.DriverManager;Importcom.mysql.jdbc.Connection; Public classcc {PrivateString url= "Jdbc:mysql://localhost:3306/ybt?useunicode=true&characterencoding=utf8"; PrivateString user= "Root"; PrivateString password= "123456"; Public voidTT ()throwsException {class.forname ("Com.mysql.jdbc.Driver"); Connection connt=(Connection) drivermanager.getconnection (URL, user, password); System.out.println (CONNT); } Public Static voidMain (string[] args)throwsException {cc C=Newcc (); C.tt (); }}
Run, console print
[Email protected]
Connection Successful!
MyEclipse connecting MySQL