64-bit CentOS6.5 under eclipse with Java connection MySQL

Source: Internet
Author: User

1. Download the JDBC driver on the official website, I downloaded the mysql-connector-java-5.0.8.tar.gz

2. Unzip the downloaded file tar-zxvf mysql-connector-java-5.0.8.tar.gz

3. Put the extracted jar package into the/usr/java/jdk1.7.0/jre/lib/ext directory, and the configuration is complete.

Test procedure:

Package test;

Import java.sql.*;

public class Mysqljava {
public static void Main (string[] arg) {
try {
Class.forName ("Com.mysql.jdbc.Driver"); Load MySQL JDBC driver
String url= "JDBC:MYSQL://127.0.0.1:3306/YHB";//Do not use host IP,YHB is the database name in MySQL
Connection conn=drivermanager.getconnection (URL, user name, password); For example (URL, "root", "123456")

System.out.println ("Connect mysql sucess!");

} catch (Exception e) {
Todo:handle exception
E.printstacktrace ();
System.out.println ("failure!");
}
}
}

If the link succeeds, it will print connect MySQL sucess!

Note: To open the MySQL service first.

64-bit CentOS6.5 under eclipse with Java connection MySQL

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.