首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

扩张ibatis的StringTypeHandler解决JDBC 对字符串超长限制

2012-10-31 
扩展ibatis的StringTypeHandler解决JDBC 对字符串超长限制解决thin JDBC 对字符串超长限制的问题。?package

扩展ibatis的StringTypeHandler解决JDBC 对字符串超长限制

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

?

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"/>

?

问题解决。

?

?

热点排行