MySQLはJavaオブジェクトを保存します
mysqlはフィールドをブロブに設定します
オブジェクトを保存し、オブジェクトをバイトにシリアル化します[]最初に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); }最後に{try {out.close(); } catch(ioException e){logger.error( "msg2bytes error!"、e); }} 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エラー!"、e); }}}オンラインの他の方法にはさまざまな問題があります。注意して使用してください。
含む:
1. URLパラメーターを設定しますautodeSerialize = true
2.SetObject(Javaインスタンスオブジェクト)クエリ
ObjectInputStream OIPS = new ObjectInputStream(rs.getBinaryStream(1));
ArrayList <String> obb =(java class)oips.readObject(); //ストリームからオブジェクトを読み取ります
読んでくれてありがとう、私はそれがあなたを助けることができることを願っています。このサイトへのご支援ありがとうございます!