BLOB与字符串的转换

public void setLayoutXmlStringToBlob(String xml){
try {
this.layoutXml = Hibernate.createBlob(xml.getBytes("utf-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
@Transient
public String getLayoutXmlBlobToString(){
if (layoutXml!=null) {
try {
byte[] bytes = layoutXml.getBytes(1l, new Long(layoutXml.length()).intValue());
return new String(bytes,"utf-8");
} catch (SQLException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return null;
}

你可能感兴趣的:(BLOB与字符串的转换)