连接mysql数据库出现下面错误的原因

来源:互联网 发布:如何测量网络成瘾 编辑:程序博客网 时间:2024/05/02 01:20

java.sql.SQLException: Access denied for user 'root,password=123456'@'localhost' (using password: NO)

今天自己试着写了下连接数据库的代码的时候出现一个问题,整了半天才发现错误的原因

         String driver="com.mysql.jdbc.Driver";
        String url ="jdbc:mysql://localhost:3306/paper?user=root,password=123456";

       Class.forName(driver);
        this.connection=DriverManager.getConnection(url);

这段代码有一处出现了错误“user=root,password=123456”这里不能用“,”连接而是用“&”,默认的“&”符合用来分隔用户名和密码的。

其实我想了下,这个还有一种写法不容易出错:DriverManager.getConnection(url,user,password);这个方法把他们分开写。