aspose file tools*
The moose likes JDBC and the fly likes how to update only the modified field values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to update only the modified field values" Watch "how to update only the modified field values" New topic
Author

how to update only the modified field values

meenu teenu
Greenhorn

Joined: Dec 05, 2006
Posts: 8
Hi friends,

I want to update only the modified field values in the database and not the values which are not modified .How to identify the fields which are modified ?
pawank gupta
Ranch Hand

Joined: Jun 07, 2006
Posts: 34
your request is not clear, could you tell which field you say modified and wich field you say not modified (against to what constraint)
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3673
    
  15
As you are asking this in a Java forum, I assume you have a Java program that reads from a database, allows the user to change the values and then saves the data back to the database. Without more details of your program it is difficult to give you more than general advice such as you will need to have flags of some sort that indicate whether the data has been changed or not and then only save data when these flags indicate that it has changed.


Joanne
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Since this is not an advanced question and has something to do with databases I'm moving it to the JDBC forum.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

Even you are updating only the modified column or all the column, you are going to execute an SQL. so it doesn't matter at all.

I guess, you need to do some heavy task for each column before it goes to database? is it so? can you explain us bit about your requirement?


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
meenu teenu
Greenhorn

Joined: Dec 05, 2006
Posts: 8
Hi,

In my application i have a java program to display more than 300 fields in the screen.If i update all the fields the system speed becomes slow so what i want is to identify the fields whose values are modified and update those modified fields alone to the database.

Kindly Please help me to solve this
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14269
    
  21

So what is exactly the question, please be more specific. Identifying which fields have changed shouldn't be too difficult - you'll have to save the original values somewhere at the beginning, and when the time comes to update the data in the database, you compare the current values with what you had before. If the value is different, then you obviously have to update it in the database.

If you want a more specific answer, then post a more specific question. What exactly is your program doing now (post some code if necessary) and which part of it exactly runs slowly?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

Is 300 fields belongs to same table?
meenu teenu
Greenhorn

Joined: Dec 05, 2006
Posts: 8
No, 300 fields belongs to different tables
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

So, the question is you want identify which table query to execute on update accroding to field which are modified?

Simple Solution is,

For JSP/Servlet application,

1. Have a hidden field for each of these fields in JSP

2. Check this hidden field value(old value) with the current value in your servlet or Action class, if it is different then you execute the query which belongs only to that table.

For Desktop application,

1. Have class which stores the old value of those fields.

2. each time when it reaches DB update, check the current value with previous value, if it is different then execute that particular query.


hth,
[ December 08, 2006: Message edited by: Prabhu venkatachalam ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to update only the modified field values