• 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)
  • 相关阅读:
    2022-06-28-冒泡排序&选择排序
    固态硬盘有缓存和没缓存之间的区别在哪
    手部数据太难找?最全手部开源数据集分享
    C#中string类型是引用类型
    GuavaCache本地缓存(LoadingCache)的使用分析
    ElementUI用el-table实现表格内嵌套表格
    Redis分布式锁解锁案例讲解
    Android 集成onenet物联网平台
    后端开发总结(1):前后端数据传输
    根视图切换动画
  • 原文地址:https://blog.csdn.net/jbb0403/article/details/127732279