发个以前写的测试用的程序,mysql可以使用本地匿名登陆,所以没有用户名密码之类的东西
// Test.javaimport java.sql.*;public class MySQL 
{
public static void main(String[] args) 
{
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String sDBName = "Mud";
try
{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Find MySQL Driver OK");
System.out.println("Get Connection ["+sDBName+"]");
conn = DriverManager.getConnection("jdbc:mysql:///"+sDBName);
System.out.println("Create Statement");
            stmt = conn.createStatement();
System.out.println("Query");
rs = stmt.executeQuery("Select * from Account");
int i = 0;
System.out.println("Start Show ResultSet");
            while (rs.next())
{
                System.out.println(i+" : "+rs.getInt(1));
i++;
            }
System.out.println("End Show ResultSet");
}
catch(Exception e)
{
System.out.println("Error");
}
finally
{
if(conn != null)
{
try
{
conn.close();
System.out.println("Close Connection OK");
}
catch(Exception e)
{
System.out.println("Close Connection Error");
}
}
}
}
}

解决方案 »

  1.   

    jdbc:mysql://localhost/mysql?user=root&password=153157
    -->
    jdbc:mysql://localhost/mysql:3306?user=root&password=153157
    再试试
      

  2.   

    你可能使和遇到同样的问题啊!你的环境是多少啊,有可能是你的MySQL和你的JDBC的版本不匹配阿
      

  3.   

    国内的文档都不对,我参考了国外文档……成功了。MYSQL 4.1+JSDK1.4
    http://mascotzhuang.go.nease.net/document/experience/MYSQLconnection.htm