Mybatis查询oracle之clob类型

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jinziweiwang/article/details/78061715

clob是大字段,可以存储文档内容,mybatis查询clob字段需要做一些处理,才可以返回字符串,可用以下方法处理:

1.public static String getClob(Object o){
  if( o == null ){
   return "";
  }
  
  oracle.sql.CLOB clob = null;
  if(o instanceof oracle.sql.CLOB){
   clob =  (CLOB) o;
  }else{
   try {
    Method method = o.getClass().getMethod("getVendorObj", new Class[]{});
    clob = (CLOB) method.invoke(o);
   } catch (Exception e) {
    e.printStackTrace();
   }
  }
  
   try {
    Reader reader = clob.getCharacterStream();
    char[] chars = new char[2048];
    int i = 0;
    StringBuffer sb = new StringBuffer();
    while( (i = reader.read(chars)) != -1){
     sb.append(new String(chars).substring(0,i));
    }
    return sb.toString();
   } catch (Exception e) {
    e.printStackTrace();
   }
  return "";
 } 

2.直接在sql上处理:

msbb.bus_num = #{NUM};

猜你喜欢

转载自blog.csdn.net/jinziweiwang/article/details/78061715