日期:2014-05-20  浏览次数:20792 次

关于mysql和jdbc的弱弱的问题
麻烦各位高手给看看到底是为什么错了?

import java.sql.*;

public class SimpleJDBC {
public static void main(String[] args) throws SQLException, ClassNotFoundException {
// Load the JDBC driver
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Driver loaded");

// Establish a connection
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/test");
System.out.println("Database connected");
}
}

错误是:
Exception in thread "main" java.sql.SQLException:Access denied for user
 ''@'localhost'(using password:NO)
到底是哪里的错误?mysql的?还是connector j的?或是我的配置有问题?

------解决方案--------------------
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/test"); 
改成
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/test","你的用户名","你的密码");
------解决方案--------------------
没有输入对数据库的用户名和密码的确认·
------解决方案--------------------
探讨
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/test");
改成
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/test","你的用户名","你的密码");