读书人

关于mysql和jdbc的题

发布时间: 2012-01-26 19:40:46 作者: rapoo

关于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","你的用户名","你的密码");

读书人网 >J2SE开发

热点推荐