Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JDBC and the fly likes Two PreparedStatement Object with Same Query Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Two PreparedStatement Object with Same Query" Watch "Two PreparedStatement Object with Same Query" New topic
Author

Two PreparedStatement Object with Same Query

velmurugan
Greenhorn

Joined: Jun 08, 2006
Posts: 24
Hi,

Every one knows that PreparedStatement is prepared once, and the precompiled version of the query is stored in the Database. (That means SQL syntax parsing done only once at the time of preparation)

If i am creating two different PreparedStstement object with the same query.

Is the second object uses the precompiled query (created by the first one) Or Both query will be parsed by the SQL parser and created a two precompiled version of query in the Database.


Please help me
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

'typically' the same query will only be compiled once, but the exact behaviour is dependent on the database. I understand Oracle matches the query String, so you should ensure they are the same.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"velmurugan",
Please check your private messages.
-DOM
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Oh, and it is also the case that a database can discard these precompiled queries to save room, so even exact matches can be compiled in the DB multiple times. I have never worried about it too much though.
 
I agree. Here's the link: jrebel
 
subject: Two PreparedStatement Object with Same Query
 
Similar Threads
Error in executeUpdate
Prepared Statement Doubt!!
Doubt about PreparedStatement
Statement and PreparedStatement question?
precompilation of PreparedStatements