今天使用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&amp;useSSL=false&amp;zeroDateTimeBehavior=convertToNull&amp;characterEncoding=UTF-8"/>

因为我是直接写在xml文件中的,要是有同学写在properties中或者yml中,请参考下面

jdbc:mysql://127.0.01:3310/test?allowMultiQueries=true&useSSL=false&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8

至此bug愉快解决。


拓展
xml中 & 是需要转义的。 把 & 转义为 &amp;
而properties和yml是不需要转义的。
当然还是建议大家把数据连接信息单独写在properties、yml中。

此bug是我开发过程中遇到的一个小问题,在此记录。若能帮到你不胜荣幸。

Cause: java.sql.SQLExceptioValue ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp相关推荐

  1. 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,默认为 ...

  2. 错误: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;刚开始 ...

  3. 关于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 ...

  4. 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 分析: ...

  5. 已解决: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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

最新文章

  1. statusStrip 状态条 toolStripStatusLabel 居右显示
  2. Exception Handling Best Practices in .NET
  3. 06.十分钟学会表达式语言EL
  4. Pytorch《GAN模型生成MNIST数字》
  5. win7系统下Loadrunner不能正常监视windows资源
  6. 和平之翼代码生成器 SMEU 版 4.0.0 RC 宝船候选版发布
  7. 51nod 1065 最小正子段和 (贪心)
  8. .Net Core中使用ref和SpanT提高程序性能
  9. ZooKeeper 到底解决了什么问题?
  10. 数据分析师人才需求的分析报告
  11. 自定义firefox账户服务器出错,我在确认 Firefox 账户时出现了问题
  12. 《Python和Pygame游戏开发指南》——导读
  13. 游戏多开检测的几种实现方法及破解方法参考
  14. Three.js线宽.lineWidth无效
  15. Hi3861 ADC驱动 如何使用开发板上的3个按键
  16. 指南-Luat二次开发教程-功能开发教程-SOCKET
  17. 能远程控制你电脑的苹果充电线正在生产和售卖,走一个?
  18. MATLAB运动目标增强
  19. 四面阿里,因为最后一个问题与offer失之交臂
  20. 在RMD使用过程中,右侧不生成图片的问题

热门文章

  1. 办公室实现无线网络全面覆盖的方案
  2. ceph cluster client(RBD)
  3. 计算机二级vbf课百度云,计算机二级易错易混选择题.
  4. 1217_使用SCons生成目标文件
  5. 老年人智能手机APP开发界面设计因素
  6. 终结符号和非终结符号
  7. php通过udp上报日志,PHP日志扩展SeasLog-1.6.0,支持TCP,UDP发送
  8. 【数据中心】容灾备份
  9. 三春过后诸芳尽. 荼蘼
  10. Linux服务器之内存过高解决思路