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?
Asked
Active
Viewed 326 times
1 Answers
2
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.

JB Nizet
- 678,734
- 91
- 1,224
- 1,255
-
If the same SQL statement is executed many times, it may be more efficient to use a PreparedStatement object. - how ? We do so many method calls to reuse our prepared statement. So why don't we just write SQL statements again and again instead. How is the performance improved by a prep statement ? – david blaine Apr 25 '13 at 08:17
-
2If, for example, you execute the same query again and again in a loop, a prepared statement will be more efficient because the execution plan of the query will be computed once by the database and then reused, instead of being recomputed for each query. – JB Nizet Apr 26 '13 at 20:48