2017-06-17 8 views
0

HTTP REST API(POST、GET、PATCHなど)リクエストと応答をデータベースエントリ(BLOBとしてのColumn)に格納する必要があります。応答は後で。JsonオブジェクトをJavaのBLOBに変換する方法

受信HTTP POST要求の一部として、DTOオブジェクトが要求本体として送信されています。リクエストボディとしてJSONオブジェクトを抽出できます。

JSONオブジェクトをJavaのBLOBに変換するにはどうすればよいですか?

+0

この質問はすでに答えを持ってい https://stackoverflow.com/questions/7947871/convert-a-string-to-a-byte-array-and-then-backオリジナルストリングとhttps://stackoverflow.com/questions/36560223/how-do-i-convert-a-jsonobject-to-a-byte-array-and-then-convert-this-byte -array-t/36560611 –

+0

この質問は、https://stackoverflow.com/questions/17400497/how-to-convert-blob-to-string-and-string-to-blob-in-javaと同じです。 – tima

答えて

0

試してみてください。この

String str = json.toString(); 
PreparedStatement ps1 = conn.prepareStatement("update table set blob=? where id=1"); 
Blob blob = conn.createBlob(); 
blob.setBytes(1, str.getBytes()); 
ps1.setBlob(1, blob); 
ps1.executeUpdate(); 
関連する問題