clob转换成String的方法总结

方法一:

public final static String clob2String(CLOB clob)
{
if (clob ==null )
{
return ;
}

StringBuffer sb = new StringBuffer(65535);//64K
Reader clobStream = null;
try
{
clobStream = clob.getCharacterStream();
char[] b = new char[60000];//每次获取60K
int 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 ;
else
return 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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值