best way to insert JSON object into DB table?

hey guys. i want to construct a json in my java code and insert it into a DB table. can i just use json in a string and replace needed values?
9 Replies
JavaBot
JavaBot5mo ago
This post has been reserved for your question.
Hey @bambyzas! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
webbdays
webbdays5mo ago
what do you mean by replace here can you please provide example here.
bambyzas
bambyzasOP5mo ago
id have json in my resources:
{
"iban": "{iban}",
"fromDate": "{fromDate}",
"toDate": "{toDate}"
}
{
"iban": "{iban}",
"fromDate": "{fromDate}",
"toDate": "{toDate}"
}
and then id do this in my code:
.replace("{iban}", iban).replace("{fromDate}", fromDate.toString()).replace("{toDate}", toDate.toString());
.replace("{iban}", iban).replace("{fromDate}", fromDate.toString()).replace("{toDate}", toDate.toString());
and it would work fine. i did the same with xml and it works fine.
webbdays
webbdays5mo ago
ok. it would be better using a Entity for that i think. iban, fromDate, toDate as attributes/table columns Also response_id column as Primary key we can call it response table. And response id as foreign key in your main table.
bambyzas
bambyzasOP5mo ago
but how can i use json as a string?
bambyzas
bambyzasOP5mo ago
bc now i have json file in my resources folder
No description
Koblížkáč
Koblížkáč5mo ago
Deserialize into entity with jackson or smth, then use save with repository
tjoener
tjoener5mo ago
Oh no no no no That's just asking for security issues. Just make a DTO, fill it and send it
JavaBot
JavaBot5mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server