Return-Path: X-Original-To: apmail-db-derby-user-archive@www.apache.org Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7F50510FF6 for ; Tue, 22 Oct 2013 12:48:50 +0000 (UTC) Received: (qmail 39250 invoked by uid 500); 22 Oct 2013 12:48:50 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 39053 invoked by uid 500); 22 Oct 2013 12:48:46 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 38847 invoked by uid 99); 22 Oct 2013 12:48:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Oct 2013 12:48:45 +0000 X-ASF-Spam-Status: No, hits=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS,UNPARSEABLE_RELAY X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of rick.hillegas@oracle.com designates 141.146.126.69 as permitted sender) Received: from [141.146.126.69] (HELO aserp1040.oracle.com) (141.146.126.69) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Oct 2013 12:48:38 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r9MCmEbn019431 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 22 Oct 2013 12:48:15 GMT Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r9MCmEjP028848 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 22 Oct 2013 12:48:14 GMT Received: from abhmt108.oracle.com (abhmt108.oracle.com [141.146.116.60]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r9MCmDCb010015 for ; Tue, 22 Oct 2013 12:48:13 GMT Received: from dhcp-whq-twvpn-1-vpnpool-10-159-151-153.vpn.oracle.com (/10.159.151.153) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 22 Oct 2013 05:48:13 -0700 Message-ID: <5266740E.7050207@oracle.com> Date: Tue, 22 Oct 2013 05:48:14 -0700 From: Rick Hillegas User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.7; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 MIME-Version: 1.0 To: derby-user@db.apache.org Subject: Re: Retrieving the 'oldest' record and deleting it References: <1382381612721-134915.post@n7.nabble.com> In-Reply-To: <1382381612721-134915.post@n7.nabble.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Source-IP: acsinet22.oracle.com [141.146.126.238] X-Virus-Checked: Checked by ClamAV on apache.org On 10/21/13 11:53 AM, Bob M wrote: > Hi > > I have the following code which retrieves the 'oldest' record and prints out > some data > > rs = s.executeQuery("SELECT from tablename ORDER BY Date ASC, Time, ASC > FETCH FIRST ROW ONLY"); > rs.next(); > String Date = rs.getString("Date"); > String Date = rs.getString("Time"); > myConsole.getOut().println("Date/Time " + Date ", " + Time); > > Now I wish to delete this record and the code is.......... > > rs = s.executeQuery("DELETE from tablename WHERE ????"); > > What is the ????? > > Bob M > > > > -- > View this message in context: http://apache-database.10148.n7.nabble.com/Retrieving-the-oldest-record-and-deleting-it-tp134915.html > Sent from the Apache Derby Users mailing list archive at Nabble.com. > Hi Bob, The following program may shed some light on how to perform positioned deletes. Hope this helps, -Rick ------------------ import java.sql.*; public class w { public static void main( String... args ) throws Exception { Connection conn = DriverManager.getConnection( "jdbc:derby:memory:db;create=true" ); conn.prepareStatement( "create table t( a int generated always as identity, b int )" ).execute(); conn.prepareStatement( "insert into t( b ) values ( 10 ), ( 20 ), ( 30 )" ).execute(); conn.setAutoCommit( false ); Statement cursorStatement = conn.createStatement(); cursorStatement.setCursorName( "MYCURSOR" ); ResultSet rs = cursorStatement.executeQuery( "select * from t where b = 20 for update" ); rs.next(); conn.prepareStatement( "delete from t where current of MYCURSOR" ).executeUpdate(); } }