thanx a lot for the various answers!
some people stated that PreparedStatements are in the context of 
the Connection (what I already suspected, as createStatement() is a method
in class Connection) so it seems that prepared statements are not the right
choice in case of connection pooling. re-creating the PreparedStatement
(perhaps each time) is of course an option - but the point does get lost
then, eh? ;o)
unless the database does cache the access path, as someone pointed out.
is there a way to find out if a certain database does this?
now for the questions:
 
> What kind of session is this? 

it is a HttpSession object used in a servlet/jsp application. 

> Do you have an application scope available to you? 
> If so, you could load your prepared statement into your 
> application scope, and it would be retained for the life of the 
> application ( rather than the life of the session ) and if your not 
> worried about to much pushing through one connection, you could even 
> throw your database connection in there

I do have apllication level scope. but I wanted to avoid storing this
information there.
the PreparedStatements contain parameters which are of course different in
each session.
and if I stored my (related) Connection object there, I could not return it
to the pool.
as i do not know when the client will issue the next request, blocking a
connection
just for the PreparedStatement does not seem like a good idea.
or did you mean "just one single Connection for the application"? this is
definitly not an option ;o)
I think it would be possible to "connect" the PreparedStatement object(s)
with the Connection
object it was created with, and try to get the same Connection from the pool
later when trying to 
execute the query (and perhaps have to wait for it because it is in use...) 
this seems to much of a hassle... I think I will think of a different way to
store queries for later use
in my sessions ;o)
thanx anyway, very interesting comments!

> > -----Original Message-----
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, July 25, 2002 4:24 PM
> > To: JDJList
> > Subject: [jdjlist] PreparedStatement
> > 
> > 
> > hi all!
> > is there anyone who can quickly answer the following question for me
> > (otherwise I will have to dig into JDBC implementation details...)
> > in one of my servlets I would like to keep PreparedStatement 
> > objects over
> > numerous calls to the same pages and just update the 
> > parameters every time.
> > e.g.
> >   Connection con = ... //obtain connection, perhaps from 
> > connection pool
> >   PreparedStatement pstmt = con.prepareStatement("SELECT * 
> > FROM any WHERE
> > some=?");
> > I keep the reference pstmt (e.g. inside the session object) 
> > for later use.
> > the connection, on the other hand, is released again (because 
> > it came from a
> > connection pool or the like, not closed!)
> > now my question is:
> > when I call something like
> >   pstmt.setInt(1,10);
> >   ResultSet rs = pstmt.executeQuery();
> > later, is it of any relevance if the connection-object that 
> > was used for the
> > creation of the PreparedStatement is back in the pool, or even used by
> > someone else in the meantime?
> > thanx & greetings to all
> > 
> > -- 
> > GMX - Die Kommunikationsplattform im Internet.
> > http://www.gmx.net
> > 
> > 
> > To change your membership options, refer to:
> > http://www.sys-con.com/java/list.cfm
> > 
> 
> To change your membership options, refer to:
> http://www.sys-con.com/java/list.cfm
> 

-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net


To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

Reply via email to