The prepared statement concept is not specific to Java, it is a
database concept. Statement precompiling means: when you execute a SQL
query, database server will prepare a execution plan before executing
the actual query, this execution plan will be cached at database server
for further execution.
The advantages of Prepared Statements are:
1. As the execution plan get cached, performance will be better.
2. It is a good way to code against SQL Injection as escapes the input values.
3. When it comes to a Statement with no unbound variables, the database
is free to optimize to its full extent. The individual query will be
faster, but the down side is that you need to do the database
compilation all the time, and this is worse than the benefit of the
faster query.
Other than training purpose it is better to use PreparedStatement to get full benefits and close all loopholes.
Difference between Statement and preparedStatement
最新推荐文章于 2022-03-21 10:00:50 发布