MySQL sets the field to blob.
Save the object, first serialize the 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 ();
Getbytes () is used to obtain the object, and the obtained byte [] is deserialized 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 methods on the Internet may have various problems. Please use them with caution.
Including:
1. Set the URL parameter autodeserialize = true
2. setobject (Java Instance Object) Query
Objectinputstream oips = new objectinputstream (Rs. getbinarystream (1); arraylist <string> OBB = (Java class) oips. readobject (); // read objects from the stream