db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John English <john.fore...@gmail.com>
Subject Re: Updating the last column in the newest record
Date Thu, 29 Jan 2015 18:48:24 GMT
On 29/01/2015 20:10, Bob M wrote:
> Hi
>
> I now have the following code but NO update takes place???
>
> psUpdate = conn.prepareStatement("update TABLE SET PROFIT_LOSS=? WHERE
> PROFIT_LOSS=?);

...which suggests that you have no rows whose PROFIT_LOSS column matches the
value of the second parameter.

You should probably use FOR UPDATE in the original SELECT:

// retrieve newest record from the table
rs = s.executeQuery("SELECT * FROM TABLE ORDER BY Trading_Date DESC,"
+ " Trading_Time DESC FETCH FIRST ROW ONLY "

                 + "FOR UPDATE OF profit_loss");  //added

rs.next();

// and now update the Profit/Loss field.............

rs.moveToCurrentRow();                          //changed
rs.updateDouble("profit_loss",profit);          //changed
rs.updateRow();                                 //changed

... or something similar (this was written off the top of my head, not tested).

-- 
John English

Mime
View raw message