• Bad format for Timestamp ‘203‘ in column 1


    突然数据库报错,完整报错内容:

    1. Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.TransientDataAccessResourceException: Error attempting to get column 'id' from result set. Cause: java.sql.SQLException: Bad format for Timestamp '203' in column 1.
    2. ; SQL []; Bad format for Timestamp '203' in column 1.; nested exception is java.sql.SQLException: Bad format for Timestamp '203' in column 1.] with root cause

    意思是,第一列的id转timestamp出现问题,可问题是,第一列id是主键int型的啊,我擦了

    查询方式

    1. QueryWrapper wrapper = Wrappers.query();
    2. wrapper.select("id, pushdate, region, region_code, pushmonth, sum(qlthl) as qlthl,
    3. sum(fnthl) as fnthl, sum(jhzs) as jhzs, sum(thsc) as thsc");
    4. wrapper.groupBy("pushmonth", "region_code");
    5. List list = kfzsdataService.list(wrapper);

    数据库:

    这件事儿牛逼就牛逼在,查11月份之前的3个月数据都好使,有11月份的数据了就不好使了。 邪了门了。

    我依次实验了几种情况,只要把11月份数据删除,就不报错。是不是和字段类型啥的有关。

    有没有可能是mybatis有bug了,我不用QueryWrapper查询,改用mapper.xml写sql语句:

    SELECT id, pushdate, region, region_code, pushmonth, SUM(qlthl) AS qlthl, SUM(fnthl) AS fnthl, SUM(jhzs) AS jhzs, SUM(thsc) AS thsc FROM quality_xxxx GROUP BY pushmonth, region_code

    也tm不好使,那是咋回事儿呢,id明明是整型,为啥要转换timestamp呢,去看了眼报错的源码:

    1. protected Timestamp getTimestampFast(int columnIndex, byte[] timestampAsBytes, int offset, int length, Calendar targetCalendar, TimeZone tz, boolean rollForward, MySQLConnection conn, ResultSetImpl rs) throws SQLException {
    2. try {
    3. Calendar sessionCalendar = conn.getUseJDBCCompliantTimezoneShift() ? conn.getUtcCalendar() : rs.getCalendarInstanceForSessionOrNew();
    4. boolean allZeroTimestamp = true;
    5. boolean onlyTimePresent = false;
    6. int year;
    7. for(year = 0; year < length; ++year) {
    8. if (timestampAsBytes[offset + year] == 58) {
    9. onlyTimePresent = true;
    10. break;
    11. }
    12. }
    13. for(year = 0; year < length; ++year) {
    14. byte b = timestampAsBytes[offset + year];
    15. if (b == 32 || b == 45 || b == 47) {
    16. onlyTimePresent = false;
    17. }
    18. if (b != 48 && b != 32 && b != 58 && b != 45 && b != 47 && b != 46)
  • 相关阅读:
    获取个人免费版Ubuntu Pro
    你所不知道的端口耗尽(一)
    SpringBoot学习笔记-配置MySQL与实现注册登录模块(中)
    一文带你了解内部开发者门户
    Python机器学习案例|梵高的《星空》图片压缩
    【C++STL基础入门】stack栈的增删查等操作的使用
    Linux修改主机名
    第十天:基于Ubuntu和gec6818开发板的QT图书管理系统完整项目设计
    Latex数学符号查表
    4.2.2-测试应用程序平台配置
  • 原文地址:https://blog.csdn.net/jbb0403/article/details/127732279