MySQL版本是8.0.3,数据库连接字符串都检查无误,驱动类名加不加cj都试过了,URL是否加时区、是否加useSSL都试过了,都无法正常登录进去!
我在运行library这个web程序登录时(我的MySQL版本是8.0.3,数据库连接字符串都检查无误,驱动类名加不加cj都试过了,URL是否加时区、是否加useSSL都试过了,都无法正常登录进去!),提示错误分如下两种情况:
1、当我使用您工程默认的mysql-connector-java(5.1.6)时,用admin/123456登录提示错误:
### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
### The error may exist in com/yanzhen/dao/AdminMapper.xml
### The error may involve com.yanzhen.dao.AdminMapper.queryUserByNameAndPassword
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
2、当我使用mysql-connector-java(8.0.9-rc)时,用admin/123456登录提示错误:
### Error querying database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'admin where username = 'admin'
and password = '123456'' at line 1
### The error may exist in com/yanzhen/dao/AdminMapper.xml
### The error may involve com.yanzhen.dao.AdminMapper.queryUserByNameAndPassword-Inline
### The error occurred while setting parameters
### SQL: select * from admin where username = ? and password = ?
### Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'admin where username = 'admin' and password = '123456'' at line 1
问题分析:
数据中的表名为admin,而admin在MySQL8.0.3中已经变成关键字了,二者冲突了。Mysql5.7没限制。其它被Mysql8占用的关键字还有:member,order,admin,leave。如果表名写成member,order,admin,leave等就会报错,暂时发现这几个...好坑呀...
解决办法:
方法(1),改掉表名,不使用关键字。
方法(2),给表名加上反单引号``符号(是tab键上方那个键)。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
2019-01-21 Qt Creator中根据为Windows系统还是Linux系统对源码进行条件编译
2019-01-21 如何在Qt Creator中导入图标资源
2019-01-21 win7/10下Qt Creator调试提示:The selected debugger may be inappropriate for the inferior的解决办法
2016-01-21 C# .NET开发图形图像程序时提示"GDI+ 中发生一般性错误"