• Mybatis使用-Error attempting to get column 'type' from result set. / '255' in column '4' is outside valid range for the datatype TINYINT.


    一、遇到的问题是这样的:

    [RemoteTestNG] detected TestNG version 6.9.10
    log4j: Parsing for [root] with value=[DEBUG,D,E,stepLog].
    log4j: Level token is [DEBUG].
    log4j: Category root set to DEBUG
    log4j: Parsing appender named "D".
    log4j: Parsing layout options for "D".
    log4j: Setting property [conversionPattern] to [%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n].
    log4j: End of parsing for "D".
    log4j: Setting property [append] to [true].
    log4j: Setting property [threshold] to [DEBUG].
    log4j: Setting property [file] to [logs/logs.log].
    log4j: setFile called: logs/logs.log, true
    log4j: setFile ended
    log4j: Appender [D] to be rolled at midnight.
    log4j: Parsed "D" options.
    log4j: Parsing appender named "E".
    log4j: Parsing layout options for "E".
    log4j: Setting property [conversionPattern] to [%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n].
    log4j: End of parsing for "E".
    log4j: Setting property [append] to [true].
    log4j: Setting property [threshold] to [ERROR].
    log4j: Setting property [file] to [logs/error.log].
    log4j: setFile called: logs/error.log, true
    log4j: setFile ended
    log4j: Appender [E] to be rolled at midnight.
    log4j: Parsed "E" options.
    log4j: Parsing appender named "stepLog".
    log4j: Parsing layout options for "stepLog".
    log4j: Setting property [conversionPattern] to [%m%n].
    log4j: End of parsing for "stepLog".
    log4j: Setting property [file] to [logs/stepLog.log].
    log4j: Setting property [append] to [true].
    log4j: Setting property [threshold] to [INFO].
    log4j: setFile called: logs/stepLog.log, true
    log4j: setFile ended
    log4j: Appender [stepLog] to be rolled at midnight.
    log4j: Parsed "stepLog" options.
    log4j: Finished configuring.
    [TestNG] Running:
    C:UserslenovoAppDataLocalTemp estng-eclipse-1408996642 estng-customsuite.xml

    Begin executing test method[com.xueersi.qa.continuation.testcase.CouponCouponGetCouponListTest . Coupon_Coupon_getCouponList_test ()] in thread[1].

    Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
    PooledDataSource forcefully closed/removed all connections.
    PooledDataSource forcefully closed/removed all connections.
    PooledDataSource forcefully closed/removed all connections.
    PooledDataSource forcefully closed/removed all connections.
    Opening JDBC Connection
    Created connection 1877986974.
    Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@6fefce9e]
    org.apache.ibatis.exceptions.PersistenceException:
    ### Error querying database. Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'type' from result set. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLDataException: '255' in column '4' is outside valid range for the datatype TINYINT.
    ### The error may exist in com/xes/qa/apitest/jcsj/db/mapper/Xes_couponsMapper.java (best guess)
    ### The error may involve com.xes.qa.apitest.jcsj.db.mapper.Xes_couponsMapper.getcouponList
    ### The error occurred while handling results
    ### SQL: SELECT id,name,code,type,valid_start_date,valid_end_date,face_value,order_full_price,receive_type,num,receive_start_time,receive_stime,receive_end_time,receive_etime, `status`,description,creater_id,create_time,modify_time FROM xes_coupons WHERE `receive_type` = 7 AND `status` = 3 AND `valid_start_date` <= SYSDATE() AND `valid_end_date` >= SYSDATE() AND `receive_stime` <= unix_timestamp(now()) AND `receive_etime` >= unix_timestamp(now()) ORDER BY `face_value` DESC, `id` DESC;
    ### Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'type' from result set. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLDataException: '255' in column '4' is outside valid range for the datatype TINYINT.
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:122)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:113)
    at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:122)
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:64)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
    at com.sun.proxy.$Proxy25.getcouponList(Unknown Source)
    at com.xes.qa.apitest.jcsj.db.dbutils.DbUtils.getXesCoupuonsList(DbUtils.java:43)
    at com.xueersi.qa.continuation.testcase.CouponCouponGetCouponListTest.Coupon_Coupon_getCouponList_test(CouponCouponGetCouponListTest.java:115)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
    at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:197)
    at org.simfast.simpletester.unitils.SimpleTesterTestNG.run(SimpleTesterTestNG.java:244)
    at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:209)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:782)
    at org.testng.TestRunner.run(TestRunner.java:632)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
    at org.testng.SuiteRunner.run(SuiteRunner.java:268)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
    at org.testng.TestNG.run(TestNG.java:1064)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
    Caused by: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'type' from result set. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLDataException: '255' in column '4' is outside valid range for the datatype TINYINT.
    at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:68)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyAutomaticMappings(DefaultResultSetHandler.java:434)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:344)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:298)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:273)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:246)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:160)
    at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:63)
    at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:78)
    at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
    at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:303)
    at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:154)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:102)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:120)
    ... 34 more
    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLDataException: '255' in column '4' is outside valid range for the datatype TINYINT.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
    at com.mysql.jdbc.Util.getInstance(Util.java:387)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:862)
    at com.mysql.jdbc.ResultSetImpl.throwRangeException(ResultSetImpl.java:7091)
    at com.mysql.jdbc.ResultSetImpl.getByteFromString(ResultSetImpl.java:1712)
    at com.mysql.jdbc.ResultSetImpl.getByte(ResultSetImpl.java:1659)
    at com.mysql.jdbc.ResultSetImpl.getByte(ResultSetImpl.java:1671)
    at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.ibatis.logging.jdbc.ResultSetLogger.invoke(ResultSetLogger.java:68)
    at com.sun.proxy.$Proxy28.getByte(Unknown Source)
    at org.apache.ibatis.type.ByteTypeHandler.getNullableResult(ByteTypeHandler.java:37)
    at org.apache.ibatis.type.ByteTypeHandler.getNullableResult(ByteTypeHandler.java:26)
    at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:66)
    ... 48 more
    Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@6fefce9e]
    Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@6fefce9e]
    Returned connection 1877986974 to pool.
    [Failed] CouponCouponGetCouponListTest.Coupon_Coupon_getCouponList_test(org.simfast.simpletester.core.TestData)[pri:0, instance:com.xueersi.qa.continuation.testcase.CouponCouponGetCouponListTest@5e316c74]
    Report directory is :D:sourcecode ew-test argetSimpleTester
    PooledDataSource forcefully closed/removed all connections.
    FAILED: Coupon_Coupon_getCouponList_test(org.simfast.simpletester.core.TestData@d278d2b)
    java.lang.NullPointerException
    at com.xueersi.qa.continuation.testcase.CouponCouponGetCouponListTest.Coupon_Coupon_getCouponList_test(CouponCouponGetCouponListTest.java:120)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
    at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:197)
    at org.simfast.simpletester.unitils.SimpleTesterTestNG.run(SimpleTesterTestNG.java:244)
    at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:209)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:782)
    at org.testng.TestRunner.run(TestRunner.java:632)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
    at org.testng.SuiteRunner.run(SuiteRunner.java:268)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
    at org.testng.TestNG.run(TestNG.java:1064)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)


    ===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
    ===============================================


    ===============================================
    Default suite
    Total tests run: 1, Failures: 1, Skips: 0
    ===============================================

    [TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 6 ms
    [TestNG] Time taken by org.testng.reporters.XMLReporter@77b52d12: 6 ms
    [TestNG] Time taken by org.testng.reporters.JUnitReportReporter@15975490: 5 ms
    [TestNG] Time taken by org.testng.reporters.EmailableReporter2@4157f54e: 3 ms
    [TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@735f7ae5: 16 ms
    [TestNG] Time taken by org.testng.reporters.jq.Main@2c6a3f77: 19 ms

    之前调通的代码一运行突然报了这样一堆的错,出错了不要紧看下问题出在哪里,于是仔细观察一番之后发现了这一堆报错中的关键信息,如下:

    确定问题之后就到代码中去看看呗,代码如下:

    mapper里面配置的代码如下:

    model里面对应数据库字段的代码如下:

    看来看去很简单的代码嘛,没什么错,这时候想到去数据库里看看吧

    询问研发老师,果然这里的字段他们调整了,增加了101,102,255,看到255再回去看报错也是跟255有关系的,基本可以确定问题引发的原因了。

    那么怎么解决呢?

    二、解决办法


    要解决问题得先理解下错误的具体原因:

    1. 网上查询资料对jdbcType这个参数的描述不多,作用不清楚,大概的意思是“jdbcType这个参数的应用场景就是,当执行mapping文件的时候,有个映射的参数为空,那么无法确定他的类型,这个时候就需要jdbcType来确定类型“。

    2. 既然jdbc Type是备用的那就不考虑调整了,于是解决思路放到了model里面的java代码上,获取到的资料如下:

        mysql中的tinyint和java中的byte的数值范围是一样的(-128~127),如果你能保证自己存储的数值不会超过这个最大值是可以的,而且tinyint只有1字节。

       既然数据库使用tinyint,肯定取值在tinyint的范围内。结果映射的时候是可以指定javaType的。 没必要使用默认的byte,完全可以用int,Integer。

     看到这里基本就确定了问题的解决办法,其实就是byte类型是-128~127,而开发在库中新加入的255超出了这个范围所以导致出错,因此修改model代码如下:

    调整完成再运行,果然问题解决了。

  • 相关阅读:
    湖南省队集训 Day 2
    一句话题解(~ 2020.4.9)
    NOIP 2017 宝藏
    NOIP 2017 逛公园
    bzoj 4767 两双手
    Codeforces Gym 101623E English Restaurant
    浅谈Tarjan算法
    Codeforces 1027F Session in BSU
    Codeforces Gym 101623A Ascending Photo
    2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution
  • 原文地址:https://www.cnblogs.com/qingqing-919/p/9414711.html
Copyright © 2020-2023  润新知