Building a Java and MySQL development environment based on eclipse

Source: Internet
Author: User

This article mainly introduces the connection between Java and MySQL .

1. Install JDK slightly ~ There are many in the garden

2. Install MySQL slightly ~

3. Download and install JDBC, download http://dev.mysql.com/downloads/connector/j/#current-tab via MySQL website

4. Install JDBC, run directly, after installation is complete: mine is the file with JDBC installed under C drive C:\Program Files\mysql\mysql Connector J

5. Open Eclipse, on the project that needs to introduce JDBC: right- click build path --

in your drive JAR where the bag is stored choose your JAR Package - Open

This is where you're going to see you. JAR The package already exists the last choice OK just fine. This way your database driver has been successfully introduced.

5. Testing

Import java.sql.*;

public class Jdbctest {

public static Connection getconnection () throws Exception {
String drivername= "Com.mysql.jdbc.Driver"; Loading the JDBC Driver
String dburl= "Jdbc:mysql://localhost:3306/test";
String username= "SA";
String password= "123456";
Class.forName (drivername);
Return drivermanager.getconnection (Dburl,username,password);
}

public static void Main (string[] Aras) {

try {
String sql= "INSERT into mytest (name,content) VALUES (' 111 ', ' xxx ')";
PreparedStatement ps=getconnection (). preparestatement (SQL);
int num = Ps.executeupdate ();
System.out.println ("OK" +num);
} catch (Exception e) {
Todo:handle exception
}

System.out.println ("successing~~~");
}
}

Building a Java and MySQL development environment based on eclipse

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.