Hi,
I have some other thoughs along the line of PreparedStatement performance. I
am going to do some testing to try to answer them myself, but I try the
thougts on this group first.
My concern is that I create new PreparedStatement-objects each time I run
the same query. It is not so stupid as it seems, maybe, but in an
application, in the data layer, I use one method to execute one query. The
method does all it own housekeeping; getting a connection from a pool,
creating and executing the query and converting the result to a Collection
or something of a "data carrier" :-). I would have liked to pool these
statements, because I do not like to create the statement over and over
again each time the method is called, but since the PreparedStatement
interface does not provide a setConnection method, it is hard to pool
PreparedStatements. I found someone who had done it (OOP Research) though,
and another simple solution could be; create a priority queue of Prepared
Statements, each using one of yuor precious connections, and when you need a
query that is not "queued", drop one of the existing and create a new one
using the old one's connection. It would be a rater easy thing to make, and
it wouldn't use more resources than a conventional connection pool, but ...
Is is worth the effort?
I haven't read any advanced details about JDBC, so therefore my questions
will propably be answered RTFM, but I try:
If I for instance create a PreparedStatement for "SELECT * FROM PERSON" in a
method. Then 10 minutes later the user does something that triggers the same
method. Will the query be compiled again in the database? The database will
probably cache the thing, but since I drop the connection between the calls
will it find the cached version during the next call? I'm sure there are
some performance penalty on the first call to a prepared statement, so if we
get "first call" all the times, I wander why the JDBC spec. doesn't give us
pooled statements (which is a more cool resource management thing than
regular connection pooling :-)
Sp1
> I am trying to test my code, which selects only one row in join tables
> of more than 40000 rows. First I didn't used the Prepared Statement
> String sql = "select * from .... where ...";
> Statement stmt = connection.createStatement();
> ResultSet rs = stmt.executeQuery(sqlStatement);
> get the row from the ResultSet
> Time to return the data: 4s
> Second I used the PreparedStatement:
> ps=connection.prepareStatement(sql);
> ps.setString( 1, "value" );
> rs = ps.executeQuery();
> time to return the data: 1min45s
> I knew the PreparedStatement is ideall for OLTP systems with many
> updates. But I was surprised to get a poor performance using it in my
> DSS system.
> Do I do any thing wrong ?
> thanks
> --
> - Mourad -
> Sent via Deja.com http://www.deja.com/
> Before you buy.