日期:2014-05-16 浏览次数:20636 次
解决thin JDBC 对字符串超长限制的问题。
?
?
分析结果见
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"/>
?
问题解决。
?
?