Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to update only the modified field values

 
meenu teenu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since this is not an advanced question and has something to do with databases I'm moving it to the JDBC forum.
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
meenu teenu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is 300 fields belongs to same table?
 
meenu teenu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, 300 fields belongs to different tables
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic