1.首先准备mysql 和eclipse环境,在环境搭建好之后,从eclipse官网下载jdbc的驱动包,下载地址http://dev.mysql.com/downloads/connector/j/
2.从下载的文件中取出mysql-connector-java-5.1.31-bin.jar,放到工程中,并导入路径
方法:右击工程名->Build Path->Configure Build Path,选择Add External JAR… 找到mysql-connector-java-5.1.31-bin.jar所在的位置,然后将驱动包加载到项目中,
3.写个例子测试一下
package testmysql;
import java.sql.*;
public class Test {
public static void main(String[] args) {
String driver = "com.mysql.jdbc.Driver";
String URL = "jdbc:mysql://localhost:3306/student";
Connection con = null;
try
{
Class.forName(driver);
}
catch(java.lang.ClassNotFoundException e)
{
System.out.println("Connect Successfull.");