Mybatis使用-Error attempting to get column 'type' from result set. / '255' in column '4' is outside ...

2023-05-16

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

[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:\Users\lenovo\AppData\Local\Temp\testng-eclipse-1408996642\testng-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\new-test\target\SimpleTester
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代码如下:

 

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

 

转载于:https://www.cnblogs.com/qingqing-919/p/9414711.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Mybatis使用-Error attempting to get column 'type' from result set. / '255' in column '4' is outside ... 的相关文章

  • 带参数的 REST GET 动词

    我正在和我的队友一起阅读一些 REST 我们正在编写一个 RoR 应用程序 它将向世界其他地方公开它的一些功能 我在这个团队的任务是制作一个公开日记报告的资源 如果你打电话 http root com journalreports http
  • jQuery 的 ajax 成功函数的额外参数

    我正在使用以下代码获取 XML 文件 function getMaps toLoad loadMaps length for var i 0 i lt loadMaps length i ajax type GET url loadMaps
  • PHP 自动“GET”变量

    我正在为我的公司设计一个新网站 我正在尝试实现切换导航 这是我过去在所有网站上使用的 由于某种原因 当我转到index php x products 时没有任何反应 它仍然显示 inc main php 换句话说 它没有从 URL 中检测到
  • 将超过 31 天的文件移至另一个驱动器

    Function Move Moves all files older than 31 days old from the Source folder to the Target Get Childitem Path E source Wh
  • Mybatis 3.0.5 嵌套集合映射示例

    我正在研究 MyBatis 3 0 5 的映射功能 运行嵌入式模式的数据库是H2 1 3 160 在用户手册的帮助下 我让简单的部分工作起来 但我很难绘制出Set使用一个HashMap作为后备存储 以下是自定义集合的 Java 代码 该集合
  • 直接使用GET和POST有哪些漏洞?

    我想知道有哪些漏洞而直接使用 GET 和 POST 变量 即没有修剪和addslashes函数和mysql转义字符串之类的东西 我的问题是 我们还需要照顾什么在使用 GET 和 POST 时 有哪些类型的攻击比如SQL注入 一般来说 不仅限
  • 使用 Java 套接字进行 GET 请求

    我正在编写一个简单的程序来向特定的 url 发送 get 请求 http badunetworks com about http badunetworks com about 如果我将请求发送到 则该请求有效http badunetwork
  • jQuery 简单值与 .val() 出现问题

    我有以下代码 document ready function alert font someClass val 这里有一个Fiddle http jsfiddle net 2wwzD 1 用它 有谁知道为什么我无法返回字体标签的值 我是否假
  • PHP 在 URL 中使用 cURL 和 GET 请求

    我使用 cURL 而不是 file get contents 它在 URL 上运行良好 直到我使用 GET 请求变量代替下面 URL 上的城市 在以下方面使用 cURL 有效 url http www weather forecast co
  • YouTube get_video_info 引发限制错误

    我已经为 joomla 创建了 是的另一个 YouTube 播放器模块 在模块后端我使用了来自的代码这个答案 https stackoverflow com a 5151862 4708062显示视频标题 不幸的是 对于大多数视频 ID g
  • 如何使用注解配置的 MyBatis 指定 IN param 类型

    如果我希望能够传递空值 我似乎需要明确告诉 MyBatis java util Date IN 参数使用什么数据库类型 但我找不到办法做到这一点 我尝试了以下不同的变体 但没有成功 Select List
  • HTML
    标签导致 Rails 表单提交 GET 而不是 POST 请求

    我有一个可以正常工作的表单 直到我添加样式标签 我正在使用 twitter bootstrap 该应用程序是 Rails 3 1 我使用的是 Mac 这是一个可以正常工作的表格 没有任何问题 div class alert message
  • jQuery 加载到变量

    我需要将 jQuery 加载结果插入到变量中 页面 ajax html 上带有 id 测试的元素的内容 result load ajax html test 尝试使用jQuery get http api jquery com jQuery
  • 我想向我的销售点的用户授予特权,但我不知道如何做,有什么建议吗?

    我有一个问题 我有一个用netBeans制作的销售点系统 2个用户可以在我的系统中注册 管理员 和 供应商 系统中有几个模块 包括 Inventario 模块允许您在数据库中输入 修改 删除和搜索文章 问题是我希望只有管理员有权限进入该模块
  • 我可以 POST 和 GET 到同一个 PHP 页面吗

    例如 我想知道是否可以在同一个 php 页面上进行 GET 和 POST 我想将数据发送到 http www example com my php 所以首先是 GET http www example com my php task dos
  • Ruby on Rails 3:如何分别检索 POST 和 GET 参数?

    我知道你可以使用获取参数params 但问题是它合并了所有参数 无论它们是通过GET or POST 如果您通过以下方式发送请求GET 没问题 参数只能挤在URL里 但如果你发送一个POST具有类似 URL 的请求 blabla foo b
  • Ruby 中的参数化 get 请求?

    如何创建 HTTPGETRuby 中带参数的请求 这很容易做到 当你POSTing require net http require uri HTTP post form URI parse http www example com sea
  • 未捕获的类型错误:未定义不是 indexOf 上的函数

    我目前有此代码来检查特定 ID 的网站 URL GET 选项 但每当运行此代码时 我都会收到一个奇怪的错误 Uncaught TypeError Undefined is not a function 这是我的代码 如果我能得到关于这个问题
  • 如何在android sdk中从图库中获取图像并将其显示到屏幕上

    我想知道如何从图库中获取预先保存的图像 然后将其显示到屏幕上 任何教程 有用的链接和信息将不胜感激 如果您希望我进一步解释任何内容 请询问 Intent photoPickerIntent new Intent Intent ACTION
  • 来自链接参数的多个 $_GET

    我使用 js 将值发送到 php 文件 如下所示 validation php firstName test lastName test email test contactNumber test title test descriptio

随机推荐