PreparedStatement, it is said offers better performance that Statement object by virtue of being "pre-compiled". When the above pre-compilation takes place, the SQL query is fine-tuned for various aspects, one among which is performance - this ofcourse, is based on the current size/contents of the table. What if the table size is so large, and the PreparedStatement is used for a large number of operations - wont the query optimization be wrong in that case ?Rather, wont this wrong optimization affect the performance in the long run ?
An execution plan can become less appropriate as the volume or composition of the data changes, but it's up to the database and/or its JDBC driver to decide how long to cache a plan for. You would hope that there is some invalidation mechanism, even if it is only a maximum age.