Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 83505 invoked from network); 28 Apr 2008 14:53:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 28 Apr 2008 14:53:27 -0000 Received: (qmail 74621 invoked by uid 500); 28 Apr 2008 14:53:28 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 74297 invoked by uid 500); 28 Apr 2008 14:53:27 -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 74286 invoked by uid 99); 28 Apr 2008 14:53:27 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Apr 2008 07:53:27 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [63.246.20.101] (HELO mail.sixfriedrice.com) (63.246.20.101) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Apr 2008 14:52:34 +0000 Received: (qmail 18918 invoked by uid 89); 28 Apr 2008 14:52:53 -0000 Received: by simscan 1.4.0 ppid: 18912, pid: 18914, t: 0.0736s scanners: regex: 1.4.0 clamav: 0.91.2/m:33/d:989 Received: from unknown (HELO ?10.0.1.191?) (geoff@sixfriedrice.com@68.3.73.169) by mail.sixfriedrice.com with ESMTPA; 28 Apr 2008 14:52:53 -0000 Message-Id: From: Six Fried Rice To: Derby Discussion Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v919.2) Subject: Paging Result Sets Date: Mon, 28 Apr 2008 07:52:52 -0700 X-Mailer: Apple Mail (2.919.2) X-Virus-Checked: Checked by ClamAV on apache.org I think this is a FAQ (indeed, it is in the FAQ with a rather terse answer) but I'm looking for a little more guidance. I need to be able to "page" the results of queries in Derby. Since Derby does not have an equivalent of MySQL's LIMIT, MSSql's TOP, or Oracle's ROW_NUM, there doesn't seem to be a way to do this on the SQL side. The recommendation is to use JDBC. I found a few mailing list responses that suggest using JDBC conventions but don't go in to much detail. I'm assuming the solution is something along these lines: 1: Calculate the starting and ending offset desired. 2: call setMaxRows() on the statement to fetch up to the *ending* offset. 3: spin through the result set until the *starting* offset is reached. 4: process records until the end of the result set. Is this the right approach? Are there any best practices to ensure that step 3 is as fast as possible? Thanks! Geoff