0

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.

As part of the incoming HTTP POST request, the DTO object is coming as request body. I can extract the JSON object as a request body.

How can I convert that JSON object to BLOB in Java?

3

1 Answer 1

0

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.