存在kingbase数据库里的是PDF文件,查询出来的blob类型为com.kingbase.jdbc3.Jdbc3Blob,如何转换成String格式?使用
byte[] b = new byte[1024 * 8];
int i = 0;
while ((i = is.read(b)) != -1) {
sb.append(new String(b, 0, i));
}
时报错java.io.IOException: Transaction exception during operate large object
at com.kingbase.largeobject.BlobInputStream.read(Unknown Source)
http://blog.csdn.net/for_china2012/article/details/9307491
large object是不是太大了。
直接new String(rs.getbytes(index));就可以。不过不理解pdf存Blob是正常的你把他转成string干啥。转成string 你也看不懂啊。
由于Blob类型存放的是字节数组,利用String的getBytes()方法获得该字符串的字节数组(注意编码方式),之后利用hibernate工具存入Blob即可。
1
2
3
4
5
6
7
8
9
10
11
12
public static Blob getBlogValue(String strValue,String charsetName){
Blob blobValue = null;
try {
//charset为“字符编码方式”
byte[] bytes=strValue.getBytes(charsetName);
System.out.println("byte[]:"+bytes);
blobValue=Hibernate.createBlob(bytes);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return blobValue;
}