I have an array of some strings in my Java code. I want to check if (and which) of the values in that array are present in the mySql database that I am using. The way I have tried to do it is query the data base for each individual value in the array. I wanted to know if there is a more efficient way of doing this? Thanks in advance.
In my java code:
String[] arrProducts=new String[]{"AB","BC","CD","AE","fg","BV","etc"};
In mySql Products database i have a productsInventory table, which has a column productId. So basically I want to check if the entire arrProduct values are present in the column productId instead of querying individually like: Select * from ProductsInventory where productId like 'AB'.
EDIT1: So my table looks like this:
ProductsInventory->{ProductName,productId}
right mow I am querying the table using one query for each value in my array.
Eg: Select * from ProductsInventory where productId like 'AB';
Select * from ProductsInventory where productId like 'BC';
Select * from ProductsInventory where productId like 'CD';
SO depending on the number of elements in my array I need to send multiple queries.
EDIT 2: And my array can change depending on user interaction. What the user enters is stored in my array and I need to check if those values are present in the database table.