From derby-user-return-2572-apmail-db-derby-user-archive=db.apache.org@db.apache.org Wed Nov 09 19:19:51 2005 Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 45725 invoked from network); 9 Nov 2005 19:19:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 9 Nov 2005 19:19:51 -0000 Received: (qmail 32974 invoked by uid 500); 9 Nov 2005 19:19:43 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 32861 invoked by uid 500); 9 Nov 2005 19:19:43 -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 Delivered-To: moderator for derby-user@db.apache.org Received: (qmail 97535 invoked by uid 99); 9 Nov 2005 17:12:20 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=UNPARSEABLE_RELAY X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Date: Wed, 09 Nov 2005 10:11:35 -0700 From: Arieh Markel Subject: Re: PreparedStatement and scope Sender: Arieh.Markel@Sun.COM To: derby-user@db.apache.org Message-id: <43722DC7.5080702@Sun.COM> MIME-version: 1.0 Content-type: text/plain; format=flowed; charset=UTF-8 Content-transfer-encoding: 7BIT X-Accept-Language: en, he, fr, fr-FR, en-GB, de-DE, ja, zh-TW, zh-CN User-Agent: Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.7) Gecko/20050530 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Thanks for the answers. I am using Derby embedded and have a single connection to the database. From you answer I am concluding that the determining factor is the connection. I guess that I can then use prepared statements in both cases - or in the event of having multiple connections (a connection pool ?), to have the prepared statements associated with each one of them. Arieh Knut Anders Hatlen wrote On 11/09/05 09:14,: > Arieh Markel writes: > > > >> Are prepared statement scoped within a transaction ? >> > > > No, you can reuse a prepared statement in another transaction (on the > same connection). > > > >> The reason for my question is as follows: >> >> - I use Derby to maintain 'regular' tables, as well as a table that is >> expected to have a single record >> >> For regular tables, I would like to use prepared statements, under the >> assumption that the RDMBS will perform proper optimizations and yield >> better performance. >> >> For 'single record', the advantage of the prepared statement (unless >> preserved >> across invocations) disappears and it may be better to just construct a >> simple Statement. >> >> Is this reasonable ? >> > > > If you perform many operations on the single-record table within the > same connection, you should use prepared statements and reuse them. If > you create a new connection every time you perform an operation on > that table, PreparedStatement won't perform better than Statement. > > -- Arieh Markel Sun Microsystems Inc. CNS CTO - Advanced Technology 500 Eldorado Blvd. MS UBRM05-169 e-mail: arieh.markel@sun.COM Broomfield, CO 80021 http://blogs.sun.com/arieh Phone: (303) 272-8547 x78547