File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes What is the best way to do simple update to a very Huge Table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "What is the best way to do simple update to a very Huge Table" Watch "What is the best way to do simple update to a very Huge Table" New topic
Author

What is the best way to do simple update to a very Huge Table

Sam Kumar
Ranch Hand

Joined: Nov 30, 2001
Posts: 38
Hi,
I need to update couple of tables to convert the existing email address into lower case. Using SQL, it is very easy to do but the problem is that these tables are very huge and contains atleast 2M records. I am not sure which is the best way to do update:
1) Using SQL, something like this
update contact set email_address = lower(email_address);
2) Using SQL, but in certain number of records.
update contact set email_address = lower(email_address) where (contact _id >= 1 and contact_id <= 10000);
commit;
update contact set email_address = lower(email_address) where (contact _id >= 10001 and contact_id <= 20000);
commit;
..............so on
3) Using Java JDBC ResultSet by updating one record at a time by scrolling ResultSet. Here the ResultSet may contain atleast 2M records and I will be reading one by one and updating record one by one.
Any suggestion which one is the best or any other alternative.
Thanks in advance.
SK
Mark Howard
Ranch Hand

Joined: Feb 14, 2001
Posts: 285
Hi Sushil
If you don't have concerns about database down time then a sweeping SQL of the entire table should do the trick. Seems overkill to have to write an application to do the work.
If you have concerns about other applications accessing/modifying the table data during the update, then you should lock the entire table prior to running the update SQL.
Two million rows is not that much for what appears to be a relatively straightforward update.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: What is the best way to do simple update to a very Huge Table
 
Similar Threads
ODBC-JDBC connection and Looping
Problem with BATCH UPDATES
ODBC - JDBC connection and Updating MY SQL
Hibernate Composite keymapping
Performance problem in jdbc