Home  >  Article  >  Database  >  连接MySQL数据库出现错误解决一例

连接MySQL数据库出现错误解决一例

WBOY
WBOYOriginal
2016-06-07 17:12:33983browse

java.sql.SQLException: Access denied for user

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

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

String driver="com.mysql.jdbc.Driver";

String url ="jdbc:mysql://localhost:3306/paper?user=root,password=www.linuxidc.com";

Class.forName(driver);

this.connection=DriverManager.getConnection(url);

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

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

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn