View Single Post

  #6 (permalink)  
Old 10-26-2007
kath
 
Posts: n/a
Default Re: how to compare array of String with column of a table

>> Load the array into a temporary table and use a MySQL intersect
I would not consider this is better idea because, there creating table
inserting values will take lot of SQL queries(statements).
- CREATE statement = 1
- INSERT statement = depending on the size of array
- DELETE statement = 1

>> 0: set up table:
>> Give the field a UNIQUE index
>> 1: delete:
>> DELETE FROM tablename WHERE fieldname NOT IN ('list','of','values');
>> 2: insert:
>> INSERT IGNORE INTO tablename (fieldname) VALUES ('list'),('of'),('values');
>> (allthough INSERT ... ON DUPLICATE KEY UPDATE ... could be more suited to
>> your needs)


Looks good. But i have doubt again, i am using JAVA to do this task. I
don't know exactly whether i can use String[] (array of String in
JAVA) in the DELETE query you have mentioned. I can construct a String
out list of String so that i can query, is it right way?.

If i get how to form a query for list of values, for above DELETE then
I as well get idea to INSERT query.

How do i form a query for list of String in JAVA?.

Thanks for your input,
best regards,
kath.

Reply With Quote