You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Bob M <rg...@orcon.net.nz> on 2013/10/23 18:03:40 UTC

Help with code please

Hi

With the following code........I have a problem when trying to delete the
'oldest' record

The SELECT query retrieves the correct record as shown by the output but I
can not
delete this record without a "FOR UPDATE" at the end of the SELECT query and
apparently
my current SELECT query type CAN NOT have the "FOR UPDATE" added ????
so what code modifications do I need to do ?

The sql error I am getting is...................
'deleteRow' not allowed because the ResultSet is not an updatable ResultSet

************************************
// retrieve and output date and time of oldest record from the table 
rs = s.executeQuery("SELECT * FROM tablename ORDER BY Date ASC, Time ASC
FETCH FIRST ROW ONLY"); 
rs.next(); 
String Date2 = rs.getString("Date"); 
String Time2 = rs.getString("Time"); 

myConsole.getOut().println("Date/Time: " + Date2 + ", " + Time2); 

// and now delete this record............. 
rs = deleteRow(); 

myConsole.getOut().println("Deleted oldest record");



--
View this message in context: http://apache-database.10148.n7.nabble.com/Help-with-code-please-tp134994.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.

Re: Help with code please

Posted by Rick Hillegas <ri...@oracle.com>.
On 10/23/13 9:03 AM, Bob M wrote:
> Hi
>
> With the following code........I have a problem when trying to delete the
> 'oldest' record
>
> The SELECT query retrieves the correct record as shown by the output but I
> can not
> delete this record without a "FOR UPDATE" at the end of the SELECT query and
> apparently
> my current SELECT query type CAN NOT have the "FOR UPDATE" added ????
> so what code modifications do I need to do ?
>
> The sql error I am getting is...................
> 'deleteRow' not allowed because the ResultSet is not an updatable ResultSet
>
> ************************************
> // retrieve and output date and time of oldest record from the table
> rs = s.executeQuery("SELECT * FROM tablename ORDER BY Date ASC, Time ASC
> FETCH FIRST ROW ONLY");
> rs.next();
> String Date2 = rs.getString("Date");
> String Time2 = rs.getString("Time");
>
> myConsole.getOut().println("Date/Time: " + Date2 + ", " + Time2);
>
> // and now delete this record.............
> rs = deleteRow();
>
> myConsole.getOut().println("Deleted oldest record");
>
>
>
> --
> View this message in context: http://apache-database.10148.n7.nabble.com/Help-with-code-please-tp134994.html
> Sent from the Apache Derby Users mailing list archive at Nabble.com.
>
Hi Bob,

My last response on the "Re: deleting a record - still a problem" thread 
showed how you can solve this problem by adding a unique key to the table.

Hope this helps,
-Rick