Hi.
Statements are associated closely with the given connection they come from.
You do not want multiple threads operating concurrently on a given statement.
If the JDBC driver caches it's statements, it will be per connection, and
presumably this cache will make sure no statement is used simultaneously
by more than one thread or at more than one place in the same stack.
If the statement cache is implemented well, then your call to prepareStatement
or prepareCall() will be quick when it can be satisfied from the cache, and
will do what needs to be done regardless.
Joe Weinstein at BEA.
Thank you very much Joseph,
Well I was beginning to suspect that this would be the answer. So I
guess I can just stop worrying about this.
Well, a new worry: why bother with preparedstaments and caching at
all? I can see it has great value for many applications, but I don't
see that I will benefit much from it in my case.
So I guess I just use regular statment objects
Thanks again,
Oskar
Hi again,
Of course, I have now found a lot of threads which discuss my concern.
Concerning my new problem (i.e. using PreparedStatements vs. regular
statments) I found this post from you Joe:
>>Hi. See the code I sent you in the previous email/post. You should
not/
>>cannot retain and use a reference to a statement that came from a
pool
>>connection that you have closed. We will disable and close any
>>statement etc that has been given to you when you close the
connection.
>>However *we* cache the real DBMS-driver prepared statement, so when
>>you call conn.prepareStatement() again, we will already have the
[quoted text clipped - 3 lines]
>>only live as long as your code has the connection reserved, but the
>>inner object is cached, and we can quickly give you a new wrapper
around
>>the cached object, the next time you get a connection from the pool.
>>Joe
(link http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=3B7C5D56.6C7
17E39%40mwwalker.com&rnum=8&prev=/groups%3Fq%3Dprepared%2Bstatements%2B%2Bperfor
mance%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D3B7C5D56.6C717E39%254
0mwwalker.com%26rnum%3D8)
If I understand you correctly here, it seems that you would recommend
using preparedstatements instead of regular statements anyway. Well,
maybe I just need to get into some actual ms measurements. Or what is
the general recommendation concerning this? My user's sessions will
generally be short lived, invlove queries from 6-8 different tables,
and then inserting/updateing 3-4 different tables. Generally user's
will not be doing the same query over and over again during a given
session.
Joseph Weinstein - 03 Oct 2003 17:06 GMT
> Hi again,
>
[quoted text clipped - 20 lines]
> >>Joe
> (link http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=3B7C5D56.6C7
17E39%40mwwalker.com&rnum=8&prev=/groups%3Fq%3Dprepared%2Bstatements%2B%2Bperfor
mance%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D3B7C5D56.6C717E39%254
0mwwalker.com%26rnum%3D8
The issue isn't what happens during a session. If every session is creating and using prepared statements
for the same SQL (different parameter values are OK), then if the connection caches prepared statements
so that each session that uses a connection re-uses a cached prepared statement, then you win.
BEA's weblogic connection pooling does this. You just code to standard JDBC, as if everything is
new, but under-the-covers regardless of whose JDBC driver is being used, we provide you with
cached Prepared statements when you do a prepareStatement() or prepareCall(). We saw *big*
application speed improvements when we did this.
Joe Weinstein at BEA
Robert Klemme - 08 Oct 2003 14:47 GMT
> > (link http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=3B7C5D56.6C7
17E39%40mwwalker.com&rnum=8&prev=/groups%3Fq%3Dprepared%2Bstatements%2B%2Bperfor
mance%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D3B7C5D56.6C717E39%254
0mwwalker.com%26rnum%3D8
>
[quoted text clipped - 6 lines]
> application speed improvements when we did this.
> Joe Weinstein at BEA
So you're essentially doing what I proposed - just much more elegantly
packaged (i.e. with a complete JDBC layer on top of the original driver).
:-)
Regards
robert
Clemens Anhuth - 04 Oct 2003 01:28 GMT
[...]
> If I understand you correctly here, it seems that you would recommend
> using preparedstatements instead of regular statements anyway.
Oskar,
using prepared statements resolves SQL injection issues too, relieving
you of escaping special characters and the like.
With best regards
Clemens Anhuth

Signature
---------------------------------------------------------------------
Clemens Anhuth com.primebase @ clemens.anhuth
SNAP Innovation Software GmbH
Altonaer Poststrasse 9a, Tel: ++49 (40) 389 044 - 0
22767 Hamburg, Germany FAX: ++49 (40) 389 044 - 44
http://www.primebase.com http://www.snap.de
---------------------------------------------------------------------