root'@'localhost 异常分析

本文详细解析了在Java开发中遇到的数据库连接错误原因及解决步骤,包括配置文件中的数据库密码错误、表名使用错误等问题,并提供了相应的解决策略。
 

这个异常出现的原因为配置文件中的数据库密码或者是dao层下的daoImpl实现方法时所使用的表名错误

解决办法:修改配置文件中的数据库密码和方法中的数据库表名

 

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1056)

    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)

    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3376)

    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3308)

    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:894)

    at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3808)

    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1256)

    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2032)

    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:729)

    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)

    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)

    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:283)

    at java.sql.DriverManager.getConnection(DriverManager.java:582)

    at java.sql.DriverManager.getConnection(DriverManager.java:207)

    at cn.twitter.dao.MessageDaoImpl.<clinit>(MessageDaoImpl.java:33)

    at cn.twitter.service.MessageServiceImpl.<init>(MessageServiceImpl.java:11)

    at org.apache.jsp.message_jsp._jspService(message_jsp.java:96)

    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)

    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)

    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)

    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)

    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)

    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)

    at java.lang.Thread.run(Thread.java:619)

 

[root@localhost ~]# sudo vi /etc/unbound/unbound.conf [root@localhost ~]# sudo unbound-checkconf # 验证配置文件语法[^1] /etc/unbound/unbound.conf:124: error: stray ':' /etc/unbound/unbound.conf:124: error: unknown keyword 'wq' read /etc/unbound/unbound.conf failed: 2 errors in configuration file [root@localhost ~]# sudo systemctl restart unbound # 重启服务 Job for unbound.service failed because the control process exited with error code. See "systemctl status unbound.service" and "journalctl -xe" for details. [root@localhost ~]# sudo systemctl status unbound # 验证运行状态 ● unbound.service - Unbound recursive Domain Name Server Loaded: loaded (/usr/lib/systemd/system/unbound.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since 四 2025-10-30 21:54:56 CST; 118ms ago Process: 6072 ExecStartPre=/usr/sbin/unbound-checkconf (code=exited, status=1/FAILURE) 10月 30 21:54:56 localhost.localdomain systemd[1]: Starting Unbound recursive Domain Name Server... 10月 30 21:54:56 localhost.localdomain unbound-checkconf[6072]: /etc/unbound/unbound.conf:124: error: stray ':' 10月 30 21:54:56 localhost.localdomain unbound-checkconf[6072]: /etc/unbound/unbound.conf:124: error: unknown keyword 'wq' 10月 30 21:54:56 localhost.localdomain unbound-checkconf[6072]: read /etc/unbound/unbound.conf failed: 2 errors in configuration file 10月 30 21:54:56 localhost.localdomain systemd[1]: unbound.service: control process exited, code=exited status=1 10月 30 21:54:56 localhost.localdomain systemd[1]: Failed to start Unbound recursive Domain Name Server. 10月 30 21:54:56 localhost.localdomain systemd[1]: Unit unbound.service entered failed state. 10月 30 21:54:56 localhost.localdomain systemd[1]: unbound.service failed. [root@localhost ~]# sudo vi /etc/unbound/unbound.conf [root@localhost ~]# # 检查配置语法 [root@localhost ~]# sudo unbound-checkconf /etc/unbound/unbound.conf:70: error: unknown keyword 'erver' /etc/unbound/unbound.conf:70: error: stray ':' /etc/unbound/unbound.conf:144: error: syntax error read /etc/unbound/unbound.conf failed: 3 errors in configuration file [root@localhost ~]# [root@localhost ~]# # 设置日志权限 [root@localhost ~]# sudo touch /var/log/unbound/unbound.log touch: 无法创建"/var/log/unbound/unbound.log": 没有那个文件或目录 [root@localhost ~]# sudo chown unbound:unbound /var/log/unbound/unbound.log chown: 无法访问"/var/log/unbound/unbound.log": 没有那个文件或目录 [root@localhost ~]# [root@localhost ~]# # 启动服务 [root@localhost ~]# sudo systemctl restart unbound Job for unbound.service failed because the control process exited with error code. See "systemctl status unbound.service" and "journalctl -xe" for details. [root@localhost ~]# sudo systemctl enable unbound Created symlink from /etc/systemd/system/multi-user.target.wants/unbound.service to /usr/lib/systemd/system/unbound.service. [root@localhost ~]# [root@localhost ~]# # 防火墙配置 [root@localhost ~]# sudo firewall-cmd --add-service=dns --permanent FirewallD is not running [root@localhost ~]# sudo firewall-cmd --reload FirewallD is not running [root@localhost ~]# # 校内域名解析测试 [root@localhost ~]# dig @127.0.0.1 www.hxx.edu +short ; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.16 <<>> @127.0.0.1 www.hxx.edu +short ; (1 server found) ;; global options: +cmd ;; connection timed out; no servers could be reached [root@localhost ~]# # 预期输出:192.168.1.12 [root@localhost ~]# [root@localhost ~]# # 校外域名解析测试 [root@localhost ~]# dig @127.0.0.1 www.baidu.com +short ; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.16 <<>> @127.0.0.1 www.baidu.com +short ; (1 server found) ;; global options: +cmd ;; connection timed out; no servers could be reached
最新发布
10-31
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值