Originally posted by Pradeep Bhat:
Hi,
I think that execution plan of Statment are stored as well.
A Statement must make an execution plan. All queries (and even all DML) need an execution plan. But there is no reason for the server to keep the execution plan in memory once the Statement has been executed. For a PreparedStatement, the server does have a reason to hold the execution plan -- at least until the client closes the PreparedStatement or Connection.
My point was that a PreparedStatement has a little extra overhead on the server side, because the server will keep the execution plan in memory until the PreparedStatement is closed. With a regular Statement, the server is free to release the execution plan as soon as the query (or statement) has been executed. So a PreparedStatement has a little more overhead on the server side.
Actually, your mileage may vary depending on the RDBMS that you use. For example, Oracle and DB2 will both keep the execution plan on the server side, even for a Statement, even after the Statemen has been executed. But even here, the database can release the execution plan if it belongs to a Statement that has already been executed. If the execution plan belongs to a PreparedStatement, the server does not know when or if that statement will be executed again.