MySQL 设置字段为 blob
保存对象,先将对象序列化为byte[] 使用 setObject(byte[] bytes) ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream out = null;
try {
out = new ObjectOutputStream(baos);
out.writeObject(Java实例对象);
} catch (IOException e) {
logger.error("msg2Bytes error!", e);
}finally{
try {
out.close();
} catch (IOException e) {
logger.error("msg2Bytes error!", e);
}
}
return baos.toByteArray();
获取对象 使用getBytes(),将获取的byte[]反序列化为Java 对象 ByteArrayInputStream bais;
ObjectInputStream in = null;
try{
bais = new ByteArrayInputStream(bytes);
in = new ObjectInputStream(bais);
return (java类)in.readObject();
}finally{
if(in != null){