1) 確定你的 MySQL 已啟動?
2) 你有沒有設定 Mysql 的 port 為 3306 以外的其它值?
有以下的程式碼試試
public static Connection GetConnection() {
Connection myConn = null; try
{
Class.fromName("org.gjt.mm.mysql.Driver").newInstance();
}
catch (Exception e)
{
System.err.pintln("Error");
e.printStackTrace();
}
try
{
String url = "jdbc:mysql://localhost/mysql?user=admin&password=admin"; // 修改成你自己的
myConn = DriverManager.getConnection(url);
}
catch (Exception e)
{
System.out.println("SQLException :"+e.getMessage());
System.out.println("SQL state :"+e.getSQLState());
System.out.println("Error Code :"+e.getErrorCode());
}
return myConn;
}

解决方案 »

  1.   

    String url ="jdbc:mysql://localhost/mysql";
    改为
    String url ="jdbc:mysql://localhost:3306/mysql?useUnicode=true&characterEncoding=gb2312";
      

  2.   

    to DennisLan(丹舟) 我的mysql已经启动(通过mysql.exe已经可以访问到),我的Port的缺是3306,我试了还是老问题to cym64039(青枫) 照你的,还是出现老问题