AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Prepared Statement

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases
View previous topic :: View next topic  
Author Message
lsrinu
Guest





PostPosted: Tue Jun 06, 2006 7:10 am    Post subject: Prepared Statement Reply with quote



Prepared Statement is used to execute a particular statement
repeatedly, but where it will be loaded, where the statement is stored,
is directly get the connection from the database, from where it
directly get the data from database
Back to top
lakshmi Ashok
Guest





PostPosted: Wed Jun 07, 2006 7:10 am    Post subject: Re: Prepared Statement Reply with quote



I could not quite understand your concern Wink but let me try..

A query plan is generated each time a query needs to be executed. What
we do with a prepared stmt is to prevent generation of this query plan
each time.

The query plan is placed in the cache of the database for some time
which is configured by the DBA.

When your code opens a connection, and tries to execute the stmt, it
first searched in the cache for the statement and if it finds it ,
executes it...and gets data from the database.

A pointer to a result set will not exist if you close the connection
itself. Hence, the actual result set could be somewhere on the DB cache
and the interface Result set could be just a pointer to that memory
..... this is a part I am also little bit confused about
Back to top
Bjorn Abelli
Guest





PostPosted: Wed Jun 07, 2006 1:57 pm    Post subject: Re: Prepared Statement Reply with quote



"lakshmi Ashok" wrote...
Quote:

A query plan is generated each time a query needs to be executed.
What we do with a prepared stmt is to prevent generation of this
query plan each time.

Not necessarily. It *can* be used in that way, but it's really up to the
implementor.

Not all databases makes those query plans...

Quote:
A pointer to a result set will not exist if you close the
connection itself. Hence, the actual result set could be
somewhere on the DB cache and the interface Result set
could be just a pointer to that memory

And that's how many drivers have it implemented, but it's not a guarantee.
Not all databases uses that kind of cursors, and even if they do, it's not a
guarantee that the driver will make use of it...

Some drivers have more thorogh documentation on what to expect from the
drivers, with possibly even more functionality built in, as the interfaces
only tells us the "minimum" requirements of the implementations.

E.g. if you use OraclePreparedStatements, there are additional getXxx and
setXxx methods to deal with the Oracle specific types.

In some drivers the implementation of Statement have even overridden the
toString method in order to get a "readable" representation of the statement
made, but this is not a requirement, so in many cases they have simply used
the inherited method from Object.

Quote:
.... this is a part I am also little bit confused about

To add to that confusion...

The interfaces ResultSet, Statement, etc, are just that, interfaces, which
are implemented by classes within the JDBC driver.

Some may make use of specific database functionality and simply "forward"
requests from Java, others may have it built into the driver itself, e.g. to
hold a collection of the results in the memory, etc...

The implementations of the interfaces varies very much, mostly depending on
which database they target.

The only thing the interfaces really guarantee, is that there will be some
sort of implementation for each method in the implementing classes, nothing
more...

/// Bjorn A



Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
Back to top
lakshmi Ashok
Guest





PostPosted: Wed Jun 07, 2006 2:21 pm    Post subject: Re: Prepared Statement Reply with quote

Am I getting this correct?
There are drivers that procure the result set into the calling program
memory space .. and will let me iterate the result set even after
releasing the connection?
Back to top
Bjorn Abelli
Guest





PostPosted: Wed Jun 07, 2006 2:35 pm    Post subject: Re: Prepared Statement Reply with quote

"lakshmi Ashok" wrote...
Quote:

Am I getting this correct?
There are drivers that procure the result set into the calling program
memory space .. and will let me iterate the result set even after
releasing the connection?

There *might* be, as this is completely up to the implementor.

But I wouldn't count on finding any such implementations, as it's not a
requirement. On the contrary, the ResultSet interface states in the API:

"A ResultSet object is automatically closed when the Statement object that
generated it is closed, re-executed, or used to retrieve the next result
from a sequence of multiple results."

http://java.sun.com/j2se/1.5.0/docs/api/java/sql/ResultSet.html

If you want a "disconnected ResultSet", you have a better chance to look
into any implementations of RowSet, e.g. CachedRowSet:

http://java.sun.com/j2se/1.5.0/docs/api/javax/sql/rowset/CachedRowSet.html


/// Bjorn A





Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.