MySQL은 Java 개체를 저장합니다
MySQL 필드를 Blob으로 설정했습니다
객체를 저장하고 바이트로 직렬화 [] 먼저 setObject (byte [] bytes)를 사용합니다.
BytearRayoutputStream Baos = 새로운 BytearRayoutputStream (); ObjectOutputStream out = null; try {out = new ObjectOutputStream (BAOS); out.writeObject (java instance 객체); } catch (ioexception e) {logger.error ( "msg2bytes error!", e); } 마침내 {try {out.close (); } catch (ioexception e) {logger.error ( "msg2bytes error!", e); }} return baos.tobytearRay (); getBytes ()를 사용하여 객체를 가져와 획득 된 바이트를 Java 개체로 삼아야합니다.
BytearrayinputStream bais; ObjectInputStream in = null; try {bais = new bytearrayinputstream (bytes); in = new ObjectInputStream (BAIS); return (java class) in.readobject (); } 마침내 {if (in! = null) {try {in.close (); } catch (ioexception e) {logger.error ( "bytes2msg error!", e); }}} 온라인으로 다른 방법에는 다양한 문제가 있습니다.주의해서 사용하십시오.
포함하다:
1. URL 매개 변수를 설정합니다. Autodeserialize = true
2. SetObject (java instance 객체) 쿼리
ObjectInputStream OIPS = New ObjectInputStream (rs.getBinaryStream (1));
ArrayList <String> OBB = (Java Class) OIPS.ReadObject (); // 스트림에서 개체를 읽습니다
읽어 주셔서 감사합니다. 도움이되기를 바랍니다. 이 사이트를 지원 해주셔서 감사합니다!