clob转换成String的方法总结

来源:互联网 发布:2017年淘宝营业额 编辑:程序博客网 时间:2024/05/09 06:00

方法一:

public final static String clob2String(CLOB clob){if (clob ==null ){return ;}StringBuffer sb = new StringBuffer(65535);//64KReader clobStream = null;try{clobStream = clob.getCharacterStream();char[] b = new char[60000];//每次获取60Kint i = 0;while((i = clobStream.read(b)) != -1){sb.append(b,0,i);}}catch(Exception ex){sb = null;}finally{try{if (clobStream != null)clobStream.close();}catch (Exception e){}}if (sb == null)return ;elsereturn sb.toString();}


方法二:

public static String clob2string(Clob c){ StringBuffer sb = new StringBuffer(1024);Reader instream = null; try{ instream = c.getCharacterStream(); char[] buffer = new char[(int)c.length()];int length = 0; while ((length = instream.read(buffer)) !=-1){ sb.append(buffer); } } catch(Exception ex){ ex.printStackTrace(); } finally{ try{ if(instream != null) instream.close(); } catch(Exception dx){ instream = null; } return sb.toString(); } } 


方法三:

public String getText(String s)throws SQLException{String s1 = "";char ac[] = new char[200];CLOB clob = (CLOB)result.getObject(s);if(clob == null)return null;Reader reader = clob.getCharacterStream();int i;try{while((i = reader.read(ac, 0, 200)) != -1)s1 = s1 + new String(ac, 0, i);}catch(Exception exception1){throw new SQLException(exception1.getMessage());}finally{try{reader.close();}catch(Exception _ex) { }}return s1;}


原创粉丝点击