Originally posted by Scott Selikoff:
From the PreparedStatement API: "A SQL statement is precompiled and stored in a PreparedStatement object. This object can then be used to efficiently execute this statement multiple times."
The alternative is a Statement in which data is not known about the query until it is executed. The common example is if you need to do 100 inserts. With a PreparedStatement you can use the same statement 100 times, just changing some of the input values inbetween update calls. With a regular statement, this is compiled at runtime and cannot be changed.
Scott,
Lets have a small pseudo code of what you said
(If we are going to insert 100 records means usually we will use the loop)
String var = "a";
String query="Insert...";
for()
{
........
preparedstatement.setString(1,var);
executeInsert
}
In the above pseudo code instead of prepared statement if I am using statement then also I can change the value at runtime like this correct ?
String var = "a";
String query="Insert..." + var;
for()
{
........
var = ...
executestatement
}
So I can assign values at runtime in both the statements then what Pre compile exactly means ?
I thought that It is for performance improvement.