• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Prepared statements question

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been thinking about prepared statements, and I have a question
In following example(psuedo, well sortoff) I have a method executing a query.

In that method i prepare a statement:



If I call this method several times, will the statement be prepared over and over again?
Thus leaving me only with the security side of the benefits of prepared statements.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Prepared Statement has a big deal on performance..As database query string which only compiles at database engine one time rather than Statement query which got compiles every time you execute query....

More on this-
PreparedStatement
 
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont think so. If you execute the query. You will only run the command:

Not the statement:

So the query is prepared only once and executed anytime!
For benefits of PreparedStatement, read this:
http://faq.javaranch.com/java/PreparedStatement
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tristan Van Poucke wrote:...
If I call this method several times, will the statement be prepared over and over again?
Thus leaving me only with the security side of the benefits of prepared statements.

It is prepared over and over, because you call it over and over. But you don't only get the security benefit.
Because you use a prepared statement with parameter binding, your database will most likely recognize this query, and reuse it's execution plan. It won't do that if you paste your values into the sql string.
 
reply
    Bookmark Topic Watch Topic
  • New Topic