Cause: java.sql.SQLExceptioValue ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp
今天使用mybatis创建demo测试的时候发现了一个有意思的bug
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'last_login_at' from result set. Cause: java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
### The error may exist in com/ssm/dzk/mapper/UserMapper.xml
### The error may involve com.ssm.dzk.service.UserService.getAll
### The error occurred while handling results
### SQL: select * from t_user
### Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'last_login_at' from result set. Cause: java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
这个异常简单的来说就是数据库时区的问题导致 ‘last_login_at’ 这个字段不能正常获取。
贴上我的xml配置
<environment id="development">
<transactionManager type="JDBC"/><dataSource type="POOLED"><property name="driver" value="com.mysql.jdbc.Driver"/><property name="url" value="jdbc:mysql://127.0.01:3310/test"/><property name="username" value="root"/><property name="password" value="root"/></dataSource>
</environment>
不知道各位发现了什么没有。
我并没有在url 配置数据库的安全链接和数据库编码格式和数据库时区
就是这个小疏忽导致的。
现在把它加上
jdbc:mysql://127.0.01:3310/test?allowMultiQueries=true&useSSL=false&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8"/>
因为我是直接写在xml文件中的,要是有同学写在properties中或者yml中,请参考下面
jdbc:mysql://127.0.01:3310/test?allowMultiQueries=true&useSSL=false&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8
至此bug愉快解决。
拓展
xml中 & 是需要转义的。 把 &
转义为 &
而properties和yml是不需要转义的。
当然还是建议大家把数据连接信息单独写在properties、yml中。
此bug是我开发过程中遇到的一个小问题,在此记录。若能帮到你不胜荣幸。
Cause: java.sql.SQLExceptioValue ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp相关推荐
- mysql解决Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp
同步发布:http://www.yuanrengu.com/index.php/mysqlsolvetimestamp.html 在使用mysql时,如果数据库中的字段类型是timestamp,默认为 ...
- 错误:Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp;的解决
问题: 代码中查询MySQL的结果集时报错,提示Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp;刚开始 ...
- 关于Value ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp异常问题的解读
前提 对于必传的字段, 新需求改为非必填的时候,在测试环境出现了 Value '0000-00-00 00:00:00' can not be represented as java.sql.Time ...
- java.sql.SQLException: Value ”0000-00-00 00:00:00“ can not be represented as java.sql.Timestamp
java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp 分析: ...
- 已解决:java.sql.SQLException: Value ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp
一.问题 一大早到公司 Mysql 中的一个 datetime 字段时碰到了一个 Cause: java.sql.SQLException: Value '0000-00-00 00:00:00' c ...
- MySQL 错误【四】Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp
1. 错误描述 在使用mysql时,如果数据库中的字段类型是timestamp,默认为0000-00-00,会发生异常:Value '0000-00-00 00:00:00' can not be r ...
- Value ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp
程序使用select 语句查询数据时,出现以下异常: java.sql.SQLException:Value '0000-00-00' can not be represented as java.s ...
- MySQL错误:Value ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp
java项目,使用MySQL,字段类型为timestamp,字段值默认为0000-00-00 00:00:00. 在解析数据时会抛出一个异常: java.sql.SQLException: Value ...
- Caused by: java.sql.SQLException: Value ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Tim
一.今天在使用Seatunnel从Mysql往Hive抽数时,报错: Caused by: java.sql.SQLException: Value '0000-00-00 00:00:00' can ...
最新文章
- statusStrip 状态条 toolStripStatusLabel 居右显示
- Exception Handling Best Practices in .NET
- 06.十分钟学会表达式语言EL
- Pytorch《GAN模型生成MNIST数字》
- win7系统下Loadrunner不能正常监视windows资源
- 和平之翼代码生成器 SMEU 版 4.0.0 RC 宝船候选版发布
- 51nod 1065 最小正子段和 (贪心)
- .Net Core中使用ref和SpanT提高程序性能
- ZooKeeper 到底解决了什么问题?
- 数据分析师人才需求的分析报告
- 自定义firefox账户服务器出错,我在确认 Firefox 账户时出现了问题
- 《Python和Pygame游戏开发指南》——导读
- 游戏多开检测的几种实现方法及破解方法参考
- Three.js线宽.lineWidth无效
- Hi3861 ADC驱动 如何使用开发板上的3个按键
- 指南-Luat二次开发教程-功能开发教程-SOCKET
- 能远程控制你电脑的苹果充电线正在生产和售卖,走一个?
- MATLAB运动目标增强
- 四面阿里,因为最后一个问题与offer失之交臂
- 在RMD使用过程中,右侧不生成图片的问题