MySQL Stores Java objects
MySQL Settings Field blob
Save object, first serialize object to byte[] using setobject (byte[] bytes)
Bytearrayoutputstream BAOs = new Bytearrayoutputstream ();
ObjectOutputStream out = null;
try {out
= new ObjectOutputStream (BAOs);
Out.writeobject (Java instance object);
} catch (IOException e) {
logger.error ("Msg2bytes error!", e);
} finally{
try {
out.close ();
} catch (IOException e) {
logger.error ("Msg2bytes error!", e);
}
}
return Baos.tobytearray ();
Gets the object using GetBytes () to deserialize the obtained byte[] into a Java object
Bytearrayinputstream Bais;
ObjectInputStream in = null;
try{
Bais = new Bytearrayinputstream (bytes);
in = new ObjectInputStream (Bais);
Return (Java Class) In.readobject ();
} finally{
if (in!= null) {
try {
in.close ();
} catch (IOException e) {
logger.error ("bytes2msg error! ", E);}}}
Other ways on the Internet will have various problems, please use caution.
Including:
1. Set URL parameters autodeserialize=true
2.setObject (Java instance object) query
ObjectInputStream oips = new ObjectInputStream (Rs.getbinarystream (1));
Arraylist<string> OBB = (Java Class) Oips.readobject ()//read object from stream
Thank you for reading, I hope to help you, thank you for your support for this site!