Ed Murray wrote:
> Could anybody explain a good way of doing the following.
> I would like to read an integer value from a database and then
> update the database value by adding a specified figure to it.
> The addition must be done before any other query can else can access
> this value. i.e. preferably in the same operation.
> I would like to do this using JDBC and try and keep it cross
> database compatible.
>
> Any help would be greatly appreciated.
>
> --
> Ed Murray
> Avenue Network Services
> hns@optushome.com.au
> + 61 2 94162140
>
>
>
>
Assume you have table `mytable' with two integer
columns: `x' and `y'. To atomicaly update `x' in row
with y == 123 you may use something like this
(just SQL, not JDBC):
select x from mytable where y=123 for update; /* locks row */
/* do something with `x' value, calculate `newvalue' */
update mytable set x=newvalue where y=123;
commit;
PS
autocommit must be `false'.
--
Regards,
Alexander Solianic