刚刚安装了mysql,想测试一下,不多说,直接上java实例测试!
测试准备:mysql-connector-java-5.1.6-bin.jar
java测试类
package test;
import java.sql.*;
public class GetConnection {
public Connection getConnection()
{
Connection conn=null;
try
{
try {
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException ex)
{
System.out.println("加载驱动程序有错误");
}
String url = "jdbc:mysql://localhost:3306/mysql?user=root&password=wb";
conn = DriverManager.getConnection(url);
System.out.println("成功连接数据库!!");
}
catch (SQLException ex1)
{
System.out.print("取得连接的时候有错误,请核对用户名和密码");
}
return conn;
}
public static void main(String[]args)
{
GetConnection getConn=new GetConnection();
getConn.getConnection();
}
}
</span>
测试结果:
mysql 安装版(64位) 免费下载地址 http://download.csdn.net/detail/lxq_xsyu/6468461#comment
mysql安装图解 http://jingyan.baidu.com/article/642c9d34aa809a644a46f717.html