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 Arieh Markel <Ar...@Sun.COM> on 2005/11/09 18:11:35 UTC
Re: PreparedStatement and scope
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 <Ar...@Sun.COM> 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