Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Amol Patil
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Amol Patil
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne,
one more question ,
Is there any specific memory area where these compiled queries are stoted?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne & Purushothaman
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic