问题
Though , PreparedStatement can do everything i.e DDL ,DML related queries with better performance than Statement.Than , why still Statement interface exist in Java API?
回答1:
Because some queries don't have any parameter, and preparing the statement and then executing it can actually be less efficient than executing the statement directly. It's also more readable and straightforward in this case to use (and potentially reuse) a single statement.
Here's what the javadoc says, BTW:
SQL statements without parameters are normally executed using Statement objects. If the same SQL statement is executed many times, it may be more efficient to use a PreparedStatement object.
来源:https://stackoverflow.com/questions/10717355/why-preparedstatement-is-preferable-over-statement