db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Myrna van Lunteren <m.v.lunte...@gmail.com>
Subject Re: Problem updating a record
Date Tue, 03 Dec 2013 06:44:17 GMT
Bob,

You're not telling us what does happen, so we're doing our best...

The missing code? Bryan said:
"call executeUpdate() on the prepared statement in order to execute it."
So, add:
     psUpdate.executeUpdate();
after setting the values, but before doing the commit. See for examples and
explanation a simple JDBC tutorial or book, for instance:
http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html


- Bryan also thinks the SQL you've written may not do what you think/want.
Perhaps you were hoping that FETCH FIRST ROW ONLY from your query would
magically trickle down to the update?
But it will not unless you make it so. So with the current update SQL
you'll end up with updating every row in the table with the same two values.
But perhaps that is what you want.

If not, there are different ways to accomplish updating just one row.
You'll have to figure out what works there yourself. Perhaps there's
another key (id) field in the table that identifies each unique row - if
so, you can get that value in your select, and change the update SQL to
have something like 'UPDATE USD_JPY SET
Return_predicted=?,Class_predicted=? where keycolumn=" + keyvalue, or maybe
"UPDATE USD_JPY SET
Return_predicted=?,Class_predicted=? where Date=" + Date1 + "and Time=" +
Time1. Or perhaps you can rework the code to use updatable cursors and use
Resultset.rsUpdaterow method - but then I think you cannot use the ORDER BY
clauses in your select. (see:
http://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html and
http://db.apache.org/derby/docs/10.10/ref/rrefsqlj41360.html#rrefsqlj41360__sqlj15384
)

HTH
Myrna


On Mon, Dec 2, 2013 at 6:15 PM, Bob M <rgmatthews@orcon.net.nz> wrote:

> It would help if you could show me the additional code I need to accomplish
> my task
>
> Bob M
>
>
>
> --
> View this message in context:
> http://apache-database.10148.n7.nabble.com/Problem-updating-a-record-tp135856p135870.html
> Sent from the Apache Derby Users mailing list archive at Nabble.com.
>

Mime
View raw message