Updating several consecutive fields in a record

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Updating several consecutive fields in a record

Bob M
Hi

So far, I have only needed to update a single field in the latest derby record with code as follows:-

// retrieve the latest trade record
rs = s.executeQuery("SELECT * FROM xxxx ORDER BY TRADE_NO DESC NULLS LAST FETCH NEXT 1 ROW ONLY");
rs.next();
String Date3 = rs.getString("Trading_Date");
int Time3 = rs.getInt("Trading_Time");
// and now update the latest trade record
s.setCursorName("MYCURSOR");
rs = s.executeQuery("SELECT PROFIT_LOSS FROM xxxx WHERE Trading_Date = '"
        + Date3 + "' AND Trading_Time = " + Time3
+ " FOR UPDATE");
rs.next();
psUpdate = conn.prepareStatement("UPDATE xxxx SET PROFIT_LOSS = ? WHERE CURRENT OF MYCURSOR");
statements.add(psUpdate);
psUpdate.setDouble(1, profit);
psUpdate.executeUpdate();
} // end of updating the latest trade record

Now, I wish to update seven consecutive fields in the latest derby record

What is the best way to recode the above section of code?
Many thanks
Bob M
Reply | Threaded
Open this post in threaded view
|

Re: Updating several consecutive fields in a record

Bryan Pendleton-3
> psUpdate = conn.prepareStatement("UPDATE xxxx SET PROFIT_LOSS = ? WHERE

>
> Now, I wish to update seven consecutive fields in the latest derby record

You can list multiple columns in the UPDATE statement:

     UPDATE my-table SET col-1=?, col-2=?, col-3=? WHERE ...

And then use multiple "setInt", "setString", etc. statements
to associate the various column values to be used for the
placeholders.

bryan


Reply | Threaded
Open this post in threaded view
|

Re: Updating several consecutive fields in a record

Bob M
Thank you Bryan

Simple and elegant :)

Bob M