| Author |
Prepared statements question
|
Tristan Van Poucke
Ranch Hand
Joined: Jun 30, 2008
Posts: 47
|
|
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.
|
 |
Kapil Mishra
Greenhorn
Joined: Oct 04, 2009
Posts: 25
|
|
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
|
SCJP 5,SCWCD 5
|
 |
Somnath Mallick
Ranch Hand
Joined: Mar 04, 2009
Posts: 471
|
|
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
|
 |
Jan Cumps
Bartender
Joined: Dec 20, 2006
Posts: 2343
|
|
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.
|
OCUP UML fundamental
ITIL foundation
|
 |
 |
|
|
subject: Prepared statements question
|
|
|