java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
时间: 2023-09-13 14:09:38 浏览: 114
java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO) 的错误提示表明用户访问被拒绝,原因是没有使用数据库密码进行连接。这个错误通常发生在使用JDBC连接数据库时,getConnection()方法的参数传递错误。在您的情况中,错误是因为在调用DriverManager.getConnection(url)方法时,忘记传递正确的用户名和密码参数。正确的使用getConnection()方法应该是:DriverManager.getConnection(url, user, password)。
解决这个问题的办法就是使用正确的getConnection()方法,传递正确的用户名和密码参数。通过仔细检查代码,确保变量名与配置文件中的变量名一致,以及在获取数据库配置文件中的变量时没有出现错误。这样就能解决这个问题了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [java.sql.SQLException: Access denied for user ‘root’@’localhost’ (using password: YES)](https://download.csdn.net/download/weixin_38609128/14832930)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [java.sql.SQLException: Access denied for user ‘‘@‘localhost‘ (using password: NO) 出现原因和解决...](https://blog.csdn.net/he19970408/article/details/108830837)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文