[英]How to convert Json object to BLOB in java
I need to store HTTP REST API (POST, GET, PATCH, etc.) requests and responses into a database entry (Column as BLOB), so that we can audit the requests and responses later. 我需要将HTTP REST API(POST,GET,PATCH等)请求和响应存储到数据库条目(列为BLOB)中,以便我们以后可以审核请求和响应。
As part of the incoming HTTP POST request, the DTO object is coming as request body. 作为传入HTTP POST请求的一部分,DTO对象作为请求主体进入。 I can extract the JSON object as a request body.
我可以将JSON对象提取为请求正文。
How can I convert that JSON object to BLOB in Java? 如何在Java中将该JSON对象转换为BLOB?
Try this 尝试这个
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.