Using PreparedStatement,
JDBC "prepares" the SQL statement for execution by parsing, compiling, and building a query execution plan.
PreparedStatement supports batch processing but Statement does not.
PreparedStatement returns PreparedResultSet but Statement returns ResultSet.
The Statement is associated with the Connection object,
while the PreparedStatement is associated with the connection pool.
PreparedStatement is always more efficient than Statement even it is used once or twice per application lifetime.
The Statement is an interface while PreparedStatement is its implementation class.
PreparedStatement interface extends the Statement interface.
If run-time variables are used in the SQL,
the Statent created with this SQL is always unique for a database, and has to be recompiled each time.
PreparedStatement pushes non-changeable part of the SQL statement into the database and
compile it once for later bindings with run-time variables.
|