日期:2014-05-20 浏览次数:20976 次
public static String ConvertBLOBtoString(Statement stmt,String jh,String kgrq,String wjrq,String zd){
String newStr = ""; // 返回字符串
long BlobLength; // BLOB字段长度
byte bytes; // BLOB临时存储字节数组
int i = 1;
try{
ResultSet rs = stmt.executeQuery("SELECT "+zd+" FROM SGZJ_SGXS WHERE JH = '"+jh+"' AND KGRQ = TO_DATE('"+kgrq+"','YY-MM-DD') AND WJRQ = TO_DATE('"+wjrq+"','YY-MM-DD')");
if(rs.next()){
Blob blob =(Blob)rs.getBlob(1);
byte msgContent=blob.getBytes(blob.length(),i);
BlobLength=blob.length();
if (msgContent==null||BlobLength==0){
return "";
}else{
while(i<BlobLength){
bytes=blob.getBytes(i,1024);
i=i+1024;
newStr=newStr+new String(bytes,"GB2312");
}
}
}rs.close();
System.out.println(newStr);
System.out.println(newStr.length());
}catch(UnsupportedEncodingException e) {
e.printStackTrace();
}catch(SQLException e) {
e.printStackTrace();
}finally{
}
return newStr;
}
oracle.sql.CLOB clob = (oracle.sql.CLOB) rs1.getClob("xxx");
BufferedReader in = new BufferedReader(clob
.getCharacterStream());
StringWriter out = new StringWriter();
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
content = out.toString();
System.out.println(content);