我在PostgreSql中创建了一个名为books的表。
CREATE TABLE books ( id integer, data json );
我的 Json:
{ "name": "Book the First", "author": { "first_name": "Bob", "last_name": "White" } }
我该如何通过Java代码将JSON插入Postgres中?
我在PostgreSql中创建了一个名为books的表。
CREATE TABLE books ( id integer, data json );
我的 Json:
{ "name": "Book the First", "author": { "first_name": "Bob", "last_name": "White" } }
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);