突然数据库报错,完整报错内容:
- 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.
- ; 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型的啊,我擦了
查询方式
- QueryWrapper
wrapper = Wrappers.query(); - wrapper.select("id, pushdate, region, region_code, pushmonth, sum(qlthl) as qlthl,
- sum(fnthl) as fnthl, sum(jhzs) as jhzs, sum(thsc) as thsc");
- wrapper.groupBy("pushmonth", "region_code");
- 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呢,去看了眼报错的源码:
- protected Timestamp getTimestampFast(int columnIndex, byte[] timestampAsBytes, int offset, int length, Calendar targetCalendar, TimeZone tz, boolean rollForward, MySQLConnection conn, ResultSetImpl rs) throws SQLException {
- try {
- Calendar sessionCalendar = conn.getUseJDBCCompliantTimezoneShift() ? conn.getUtcCalendar() : rs.getCalendarInstanceForSessionOrNew();
- boolean allZeroTimestamp = true;
- boolean onlyTimePresent = false;
-
- int year;
- for(year = 0; year < length; ++year) {
- if (timestampAsBytes[offset + year] == 58) {
- onlyTimePresent = true;
- break;
- }
- }
-
- for(year = 0; year < length; ++year) {
- byte b = timestampAsBytes[offset + year];
- if (b == 32 || b == 45 || b == 47) {
- onlyTimePresent = false;
- }
-
- if (b != 48 && b != 32 && b != 58 && b != 45 && b != 47 && b != 46)