import java.sql.*;public class TestJDBC {  
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
    } catch (Exception ex) {
     ex.printStackTrace();
    }
    
    try {
        Connection conn = 
           DriverManager.getConnection("jdbc:mysql://localhost/mysql" + "user=root&password=root");            
                   Statement stmt = conn.createStatement();
           ResultSet rs = stmt.executeQuery("select * from dept");
           while(rs.next()){
            System.out.println(rs.getString("dname"));
            System.out.println(rs.getInt("deptno"));
           }
    } catch (SQLException ex) {
     System.out.println("SQLException: " + ex.getMessage());
        System.out.println("SQLState: " + ex.getSQLState());
        System.out.println("VendorError: " + ex.getErrorCode());
    
    } }
}程序如上,运行后抛异常
SQLException: Access denied for user ''@'localhost' (using password: NO)
SQLState: 28000
VendorError: 1045
但我的mysql的用户名和密码确实root 和root;
在mysql里敲
mysql> select host,user,password from mysql.user;
+-----------+------+-------------------------------------------+
| host      | user | password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
+-----------+------+-------------------------------------------+
无语了,实在无法解决。谢谢您们!