首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

关于mysql和jdbc的题

2012-01-26 
关于mysql和jdbc的弱弱的问题麻烦各位高手给看看到底是为什么错了?import java.sql.*public class Simple

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

热点排行