• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

deleting multiple comma separated values in one attempt

 
shahin Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I want to delete few records from a table whose id's will be passed at run time i want this operation to be done at once
can i have a method to do so
delete from tablename where id /in = HERE I HAVE TO PASS , SEPARATED MULTIPLE VALUES using jdbc

Thanks
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"shanu",

We're a friendly bunch at the Ranch, but we require members to have real display names.

Please see your previous warning here.

We require display names to be two words: your first name, a space then your last name. Fictitious names are not allowed.

You can change your display your display name here.

thanks,
Dave.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably the easiest is to use a sql batch, since you can also use a PreparedStatement. Performance is typically very good (whatever that means)

or you can use

delete from my_table where table_id in (1, 2, 3, 4, etc);

If they are string values you will need single quotes:

delete from my_table where table_id in ('1', '2', '3', '4', etc);
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic