I have created a table books in PostgreSql.
CREATE TABLE books ( id integer, data json );
My Json:
{ "name": "Book the First", "author": { "first_name": "Bob", "last_name": "White" } }
How can i insert json into Postgres via java code?
Thank you :).This really helped me to resolve the issue.
String json = "{ \"name\": \"Book the First\", \"author\": { \"first_name\": \"Priya\", \"last_name\": \"White\" } }";
PGobject jsonObject = new PGobject();
jsonObject.setType("json");
jsonObject.setValue(json);
PreparedStatement stmt=c.prepareStatement("insert into books values(2,?)");
stmt.setObject(1, jsonObject);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With