[转帖]ibatis-数据类型超最大值 _Android, Python及开发编程讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  Android, Python及开发编程讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 2159 | 回复: 0   主题: [转帖]ibatis-数据类型超最大值         下一篇 
    本主题由 koei123 于 2015-2-5 17:35:25 移动
gunrose
注册用户
等级:新兵
经验:36
发帖:79
精华:0
注册:2011-7-21
状态:离线
发送短消息息给gunrose 加好友    发送短消息息给gunrose 发消息
发表于: IP:您无权察看 2014-12-26 11:00:19 | [全部帖] [楼主帖] 楼主

解决thin JDBC 对字符串超长限制的问题。

原始错误是:

org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [17070];
--- The error occurred in com/sinosoft/card/cardKind/db/dao/IC_CARDKINDNOTIFY_SqlMap.xml.
--- The error occurred while applying a parameter map.
--- Check the IC_CARDKINDNOTIFY.abatorgenerated_insert-InlineParameterMap.
--- Check the parameter mapping for the 'value' property.
--- Cause: java.sql.SQLException: 数据大小超出此类型的最大值: 2986; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/sinosoft/card/cardKind/db/dao/IC_CARDKINDNOTIFY_SqlMap.xml.
--- The error occurred while applying a parameter map.
--- Check the IC_CARDKINDNOTIFY.abatorgenerated_insert-InlineParameterMap.
--- Check the parameter mapping for the 'value' property.
--- Cause: java.sql.SQLException: 数据大小超出此类型的最大值: 2986
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:124)
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:322)


分析结果见

http://blog.csdn.net/ruanee/archive/2006/03/24/637213.aspx
http://www.tomjamescn.cn/?p=63


后面的文章直接hack了ibatis的StringTypeHandler,完全没有必要

我的解决方法:1、扩展StringTypeHandler为LargeStringTypeHandler

Java代码 复制代码 收藏代码

package com.xxxx.component.ibatis.typehandler;
import java.io.StringReader;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.ibatis.sqlmap.engine.type.StringTypeHandler;
/**
* For using LargeStringTypeHandler, you must add a line in SqlMapConfig.xml as following:<br/>
* &lt;typeHandler javaType="java.lang.String" callback="com.sinosoft.component.ibatis.typehandler.LargeStringTypeHandler"/&gt;
* @author airlink
* @see http://blog.csdn.net/ruanee/archive/2006/03/24/637213.aspx
* @see http://www.tomjamescn.cn/?p=63
*/
public class LargeStringTypeHandler extends StringTypeHandler {
      public void setParameter(PreparedStatement ps, int i, Object parameter, String jdbcType)
      throws SQLException {
            String s = (String)parameter;
            if (s.length() < 667) {
                  //assume that all characters are chinese characters.
                  super.setParameter(ps, i, parameter, jdbcType);
            }else{
            //use setCharacterStream can insert more characters.
            ps.setCharacterStream(i, new StringReader(s), s.length());
      }
}
}
[java] view plaincopy
package com.xxxx.component.ibatis.typehandler;
import java.io.StringReader;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.ibatis.sqlmap.engine.type.StringTypeHandler;
/**
* For using LargeStringTypeHandler, you must add a line in SqlMapConfig.xml as following:<br/>
* &lt;typeHandler javaType="java.lang.String" callback="com.sinosoft.component.ibatis.typehandler.LargeStringTypeHandler"/&gt;
* @author airlink
* @see http://blog.csdn.net/ruanee/archive/2006/03/24/637213.aspx
* @see http://www.tomjamescn.cn/?p=63
*/
public class LargeStringTypeHandler extends StringTypeHandler {
      public void setParameter(PreparedStatement ps, int i, Object parameter, String jdbcType)
      throws SQLException {
            String s = (String)parameter;
            if (s.length() < 667) {
                  //assume that all characters are chinese characters.
                  super.setParameter(ps, i, parameter, jdbcType);
            }else{
            //use setCharacterStream can insert more characters.
            ps.setCharacterStream(i, new StringReader(s), s.length());
      }
}
}


2、在SqlMapConfig.xml中添加一行

<typeHandler javaType="java.lang.String" callback="com.sinosoft.component.ibatis.typehandler.LargeStringTypeHandler"/>


问题解决。

--转自 北京联动北方科技有限公司



该贴由koei123转至本版2015-2-5 17:35:25



赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论