• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to validate each json array object against Database column in java?  RSS feed

 
Mohammad Alam khan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting the below JSON response from a request.

{
    "fieldA": "value1",
    "fieldB": 2456,
    "name": "abcdefg",
    "identifiers": ["1234567889", "456748932651", "0998947372"],
    "address": "youraddress"
}
The value for each "identifiers" field has a column (column name "dst_id") mapped to a oracle database table. There is another column "status" in the same table whose value can be "A","P","R" etc. I need to write in java how to validate what is the value of Status column against each "identifiers" value.

Example : the identifier value "1234567889" has the value "P". I need to validate that. Assuming i have the code to connect to DB using jdbc. All i need is iteration of each "identifiers" field and validating what is the value for its respective "status" column. Please help me here.
 
Dave Tolls
Ranch Hand
Posts: 2839
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know SQL?

How many identifiers are there likely to be in a single JSON?

Are you also checking whether they exist or not?

Assuming nothing unusual about the above (ie several thousand identifiers) then building up a PreparedStatement with an IN clause with a number of placeholders equal to the number of identifiers.
Have it return the identifier and the status for each row.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!