On 23.06.2010 12:33, Lew wrote:
gk wrote:
Please see this ..
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/PreparedStatement.html
PreparedStatement : An object that represents a precompiled SQL
statement.
"precompiled SQL statement" ... who compiled this ?
There are a couple of layers of compilation, one at the JDBC layer
(potentially) and the other at the DBMS server.
Precompilation is not the only benefit of prepared statements.
Is it working like this way ...when I first execute the code below
DBMS compiles when it encounter for the first time and then next time
DBMS does not compile . So, We call it precompiled.
Roughly speaking, yes, although the full truth is somewhat more
complicated.
It is important to mention that for PS to work efficiently the statement
must be kept in user code. Invoking prepareStatement() with the same
string argument twice makes no guarantees about saving compilation in
the DB. To make the code efficient user must prepare the statement and
keep it around for recurring use.
That is, if you want to benefit from compilation savings - if it is only
for avoidance of SQL injection / proper conversion of arguments and
performance does not matter you can recreate PS over and over again-
prepared statement is not reused.