PreparedStatement returns PreparedResultSet but Statement returns ResultSet.
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.
PreparedStatement interface extends the Statement interface.
Using PreparedStatement,
JDBC "prepares" the SQL statement for execution by parsing, compiling, and building a query execution plan.
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.
The Statement is associated with the Connection object,
while the PreparedStatement is associated with the connection pool.
PreparedStatement supports batch processing but Statement does not.
|