my dog learned polymorphism*
The moose likes JDBC and the fly likes In PreparedStatement how it is detected that query has been changed? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "In PreparedStatement how it is detected that query has been changed?" Watch "In PreparedStatement how it is detected that query has been changed?" New topic
Author

In PreparedStatement how it is detected that query has been changed?

Amol Patil
Greenhorn

Joined: Aug 30, 2004
Posts: 8
Dear All,
I have one doubt in PreparedStatement.
In PreparedStatement query is not compiled every time.
If we change the query then it is compiled again.
How it is detectd that Query has been changed?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30356
    
150

Amol,
Welcome to JavaRanch!

You define the SQL when you run conn.prepareStatement(). Whenever such a call occurs, the driver sees if that String is already prepared in memory. If not, it creates a new one.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Amol Patil
Greenhorn

Joined: Aug 30, 2004
Posts: 8
Thanks Jeanne,
one more question ,
Is there any specific memory area where these compiled queries are stoted?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30356
    
150

Amol,
Probably, but I have no idea where. One of the advantages of a "black box" is that the caller doesn't need to know these things.
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
PreparedStatements make sense only in the DB Servers which supports SQL with bind variables. The compiled query is stored in the DB Cache and not in the middle tier. Prepared statements must be just calling the underlying methods to
- Parse the query string into a cursor variable
- bind the variables (extra step when compared to Statement)
- execute the query
- close the cursor.

and they don't maintain any metadata about the SQL. Moreover it doesn't make sense to have DB internal structure details in the Java Objects.
Amol Patil
Greenhorn

Joined: Aug 30, 2004
Posts: 8
Thanks Jeanne & Purushothaman
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: In PreparedStatement how it is detected that query has been changed?