写入:接收字符串转换Blob (亲测)
String blobStr = request.getParameter(
"textHouse");
ByteArrayOutputStream bt =
new ByteArrayOutputStream();
ObjectOutputStream ob;
try {
ob=
new ObjectOutputStream(bt );
ob.writeObject(blobStr);
}
catch (IOException e) {
e.printStackTrace();
}
Blob blob= Hibernate.createBlob(bt.toByteArray());
读取:接收Blob转换字符串 (亲测)
String content =
"";
Blob bl = hou.getTexthouse();
byte[] inbyte=
null;
if(bl
instanceof Blob){
Blob blob = (Blob) bl;
if (blob !=
null) {
inbyte = blob.getBytes(
1, (int) blob.length());
}
content =
new String (inbyte,
"UTF-8");
if(content!=
null){
content = content.substring(
7,content.length()-
1);
}
}
具体可以写成两个方法方便调用
转载请注明原文地址: https://ju.6miu.com/read-678690.html