I am reading data from database using JDBC. data is like below.
I have to insert this data into an application using Post API. for that I need to write data into file in the format API accepts.
so I will create OrgName.json file in the below format.
{
"delete": [
{
"canonicalName": "TCS"
}
],
"update": [
{
"canonicalName": "Wipro tech"
"synonyms": [
"Wipro technology"
]
},
{
"canonicalName": "Infosys"
"synonyms": [
"Infosys tech"
]
}
]
"add": [
{
"canonicalName": "Apple Computers",
"synonyms": [
"Apple"
]
},
{
"canonicalName": "Google India",
"synonyms": ["Google"]
}
]
}
So there would be 3 grouping. All the update values will come in update tag, add values in add tag based on OPERATION column and delete in delete tag. ORGNAME value of column will be canonicalName name in file. If synonyms is null then it will not be present else it will be there.
I know JDBC in java. I can read data using executeQuery of Preparedstatement and can display in console using sysout. But I am not able to write data into file in the above format.
Can anybody help me? I am database developer so not able to think how can I do it. Even minimal help would be a lot for me.
I want to convert Resultset into above file, which I am not able to do.
