解决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
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/>
* <typeHandler javaType="java.lang.String" callback="com.sinosoft.component.ibatis.typehandler.LargeStringTypeHandler"/>
* @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"/>
问题解决。
分享到:
相关推荐
ibatis 拼接字符串
NULL 博文链接:https://wuxiubing.iteye.com/blog/1010635
NULL 博文链接:https://fuchao01.iteye.com/blog/551438
整合了springmvc,hibernate,ibatis,jdbc等技术的强大框架,写的非常全面,谢谢老邵的成果。
ibatis 乱码解决 ibatis乱码 gbk iso_8859_1 乱码
Mybatis Mapper.xml中字符串形式传参,逗号分隔 AND中拼接OR。
ibatis sql语句对条件中特殊字符% # 处理
大家都要用到IBATIS框架时,连接到MYECLIPSE驱动JAR包
一直以来ibatis的分页都是通过滚动ResultSet实现的,应该算是逻辑分页吧。逻辑分页虽然能很干净地独立于特定数据库,但效率 在多数情况下不及特定数据库支持的物理分页,而hibernate的分页则是直接组装sql,充分...
iBATIS基于JDBC的半自动化持久层框架.ppt
ibatis学习 ibatis总结 ibatis ibatis ibatis
在网上一个牛人翻译的ibatis in action,他分成了几个内容来翻译,我感觉不错,就把各部分分开弄成了word格式,还没翻译完,但是现有的翻译的部分就值得我们研究了。很适用的东西,还附带有代码。大家看看
ibatis 用HashMap解决Ibatis未知列名和列数的查询结果的resultClass映射
NULL 博文链接:https://foxpro.iteye.com/blog/435001
ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料
在用iBatis.net与数据库打交道的过程中,发现iBatis.net拼接字符串不能直接拷贝然后在dbms里执行
ibatis3.0中in的用法ibatis3.0中in的用法ibatis3.0中in的用法ibatis3.0中in的用法
Spring与iBATIS的集成 iBATIS似乎已远离众说纷纭的OR框架之列,通常人们对非常流行的Hibernate情有独钟。但正如Spring A Developer's Notebook作者Bruce Tate 和Justin Gehtland所说的那样,与其他的OR框架相比...
ibatis demo,ibatis例子,ibatis示例