clob转换成String

方法一:

<wbr>public finalstatic String clob2String(CLOB clob)<br><wbr>{<br><wbr><wbr><wbr>if (clob ==null )<br><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr>return ;<br><wbr><wbr><wbr>}<br><wbr><wbr><wbr><br><wbr><wbr><wbr>StringBuffer sb = new StringBuffer(65535);//64K<br><wbr><wbr><wbr>Reader clobStream = null;<br><wbr><wbr><wbr>try<br><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr>clobStream = clob.getCharacterStream();<br><wbr><wbr><wbr><wbr><wbr>char[] b = new char[60000];//每次获取60K<br><wbr><wbr><wbr><wbr><wbr>int i = 0;<br><wbr><wbr><wbr><wbr><wbr>while((i = clobStream.read(b)) != -1)<br><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>sb.append(b,0,i);<br><wbr><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr>}<br><wbr><wbr><wbr>catch(Exception ex)<br><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr>sb = null;<br><wbr><wbr><wbr>}<br><wbr><wbr><wbr>finally<br><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr>try<br><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>if (clobStream != null)<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>clobStream.close();<br><wbr><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr><wbr><wbr>catch (Exception e)<br><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr>}<br><wbr><wbr><wbr>if (sb == null)<br><wbr><wbr><wbr><wbr><wbr>return ;<br><wbr><wbr><wbr>else<br><wbr><wbr><wbr><wbr><wbr>return sb.toString();<br><wbr>}</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

方法二:
<wbr><wbr><wbr><br><wbr>public<wbr><wbr>static<wbr><wbr>String<wbr><wbr>clob2string(Clob<wbr><wbr>c)<wbr><wbr><wbr><wbr><br><wbr>{<wbr><wbr><wbr><wbr><br><wbr>StringBuffer<wbr><wbr>sb<wbr><wbr>=<wbr><wbr>new<wbr><wbr>StringBuffer(1024);<wbr><wbr><br><wbr>Reader<wbr><wbr>instream<wbr><wbr>=<wbr><wbr>null;<wbr><wbr><br><wbr>try{<wbr><wbr><br><wbr>instream<wbr><wbr>=<wbr><wbr>c.getCharacterStream();<wbr><wbr><br><wbr>char[]<wbr><wbr>buffer<wbr><wbr>=<wbr><wbr>new<wbr><wbr>char[(int)c.length()];<wbr><wbr><br><wbr>int<wbr><wbr>length<wbr><wbr>=<wbr><wbr>0;<wbr><wbr><br><wbr>while<wbr><wbr>((length<wbr><wbr>=<wbr><wbr>instream.read(buffer))<wbr><wbr>!=<wbr><wbr>-1){<wbr><wbr><br><wbr>sb.append(buffer);<wbr><wbr><br><wbr>}<wbr><wbr><br><wbr>}<wbr><wbr><br><wbr>catch(Exception<wbr><wbr>ex){<wbr><wbr><br><wbr>ex.printStackTrace();<wbr><wbr><br><wbr>}<wbr><wbr><br><wbr>finally{<wbr><wbr><br><wbr>try{<wbr><wbr><br><wbr>if(instream<wbr><wbr>!=<wbr><wbr>null)<wbr><wbr>instream.close();<wbr><wbr><br><wbr>}<wbr><wbr><br><wbr>catch(Exception<wbr><wbr>dx){<wbr><wbr><br><wbr>instream<wbr><wbr>=<wbr><wbr>null;<wbr><wbr><br><wbr>}<wbr><wbr><br><wbr>return<wbr><wbr>sb.toString();<wbr><wbr><br><wbr>}<wbr><wbr><br><wbr>}<wbr><wbr><br><wbr>方法三:<br><br><wbr><wbr><wbr>public String getText(String s)<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>throws SQLException<br><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>String s1 = "";<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>char ac[] = new char[200];<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>CLOB clob = (CLOB)result.getObject(s);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>if(clob == null)<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>return null;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Reader reader = clob.getCharacterStream();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>int i;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>try<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>while((i = reader.read(ac, 0, 200)) != -1)<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

你可能感兴趣的:(String)