Java connects to MySQL via JDBC

Source: Internet
Author: User
Tags mysql download

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

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