today try to build Java through the JDBC connection to MySQL, the test succeeded, summed up the specific method of the connection.
fristly: First, you must install the JDK (JDK on the official website, I use the jdk1.8.0_60), the installation of attention to the configuration of environment variables.
Second: Download install MySQL, the installation process is very simple not to elaborate, note that during the installation process will be set user name and password, in-woo remember, in the use of MySQL and Java connection to MySQL will be used, my user name and password are "root."
Third: Download the JDBC driver package
Mysql-connector-java-5.1.26.zip This is a relatively new version, to the official website can be downloaded, unzip it anywhere (I was extracted to the D-Disk JDK folder, it is recommended to extract to the JDK folder you installed), Download the Unzip folder to find mysql-connector-java-5.1.26-bin.jar copy its path. Add the path to Classpath. (Classpath is not case-sensitive). Here's how:
"My Computer"--"right Button Properties"-"Advanced system Settings"-"Environment variables" found in System variables classpath Click Edit, add D:\JDK\mysql-connector-java-5.1.26 on the last side \mysql-connector-java-5.1.26-bin.jar add ";" before adding this string to separate from the previous Classpath area. And then determine.
Fourth: Using MySQL to create a database, I already have a database named students.
Fifth: Finally, you can write a. Java program, here is a link to the MySQL program and part of the analysis.
//driver name that needs to be loaded
private static final String Databasedriver = "Com.mysql.jdbc.Driver";
//url Point to the name of the database to be accessed, my database is named students
private static final String Databaseurl = "jdbc:mysql://localhost:3306/students";
//user name set when MySQL is installed
private static final String Databaseuser = "root";
//install MySQL is the password set
private static final String DatabasePassWord = "root";
//load MySQL database driver
//Connect MySQL database
source file:
Operation Result:
Related Download Links:
jdk Download: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Eclipse Download: http://www.eclipse.org/downloads/
mysql Download: http://dev.mysql.com/downloads/mysql/
connector/j Download: http://dev.mysql.com/downloads/connector/j/
Java connects to MySQL via JDBC