i have a clients table with 2 columns
CREATE TABLE clients
(
client_id serial primary key,
name VARCHAR(40) not null
)
i have a json data like
[{client_id:"1",name:"Rick"},{client_id:"2",name:"Carlin"}]
Now i need to use this json to parse and insert into my client table. How can i do it using jsp servlets and postgres database.
If you want to do it on PostgreSQL (9.3+) side, you can use the json_populate_recordset function:
insert into clients
select *
from json_populate_recordset(
null::clients,
'[{client_id:"1",name:"Rick"},{client_id:"2",name:"Carlin"}]'
)
Although, that's usually not a good idea to manually insert values to a serial column.
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