How can I know from java whether a record is updated when update query is called. I had tried the return type int from executeUpdate() but it will show 1 whenever the query is executed. That is if the record is changed or not it will return value > 1. If there is an opportunity for trigger in postgresql for calling a java method() would be helpful for this. Please help.
-
What do you mean by updated? When some column value has been changed?user180100– user1801002016-08-03 05:14:58 +00:00Commented Aug 3, 2016 at 5:14
-
I want to know which column is affected by the updateAntony Joslin– Antony Joslin2016-08-03 05:40:44 +00:00Commented Aug 3, 2016 at 5:40
-
@AntonyJoslin Why? What's the end result you're looking for? What will you do with the information that some column(s) were updated?Kayaman– Kayaman2016-08-03 05:42:06 +00:00Commented Aug 3, 2016 at 5:42
-
Its for popping up a window to show another user that a column which both working have been updated.Antony Joslin– Antony Joslin2016-08-03 05:47:13 +00:00Commented Aug 3, 2016 at 5:47
-
Its like popping up window of facebook when some one shares or likes our post.Antony Joslin– Antony Joslin2016-08-03 05:48:00 +00:00Commented Aug 3, 2016 at 5:48
2 Answers
If you need to know whether a row's data was changed as a result of the update, you would need to pass the parameters to the WHERE clause, making a statement such as UPDATE foo SET bar = $1, baz = $2 WHERE bar <> $1 AND baz <> $2 AND id = $3. Example is assuming you wish to update two columns of a single row based on id.
After that the only way the WHERE clause will match is if there is an actual update to do, and you can use the return value to check if an update occurred or not.
Another possibility is to refactor your code so that you don't need to bother about it, but you will need to explain your use case further for that.