db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adam Bovill" <abov...@fnfr.com>
Subject RE: Derby select query speed questions
Date Wed, 18 Apr 2007 22:09:52 GMT
In my application, I have a blocking queue that different processes can add database tasks
to.  We need this because we need to have the application start up instantly and not wait
a few seconds for the DB to initialize.

There is one process that handles all database operations and takes items off the queue and
runs them.

So this queue could have several items on it.  These items at the moment are just the PreparedStatement,
with its values set.  The issue is that I only have one instance of the PreparedStatement
now.  So if I reset the parameters on it or do anything like that while one item is in the
queue, it would effect both items in the queue.

One option that I have would be to queue up the PreparedStatement and the values that should
be set.  Then when it goes to execute, it sets the parameters and executes the query.  

What I was wondering was whether I could make a copy of the already prepared statement and
just set the values on that copy.  Thereby avoiding the statement compile time.



-----Original Message-----
From: Oystein.Grovlen@Sun.COM [mailto:Oystein.Grovlen@Sun.COM] 
Sent: Saturday, April 14, 2007 1:11 AM
To: Derby Discussion
Subject: Re: Derby select query speed questions

Adam Bovill wrote:
 > Hi Olav,
 > Thanks.  That seems to have improved things.
 > I was wondering whether or not there was a way to create one 
PreparedStatement from another.  I have the first one that I've created 
and would like to clone or duplicate this, w/o needing to recompile it.
 > So when I'm using a PreparedStatement, I can set the parameters w/o 
incurring too much of a penalty because it's already compiled?

In order to answer this it would be good to know a bit more about what
you are trying to achieve.  Why do need several prepared statements?
Note that a prepared statement is local to a connection.  If you want
to execute the same statement in another connection, you will have to
prepare it for that connection.  However, Derby has a statement cache
so if the statement is lexically equal to a previous statement, the
result of the previous compilation will be reused, and recompilation
will not be needed.


View raw message