Are there any disadvantages using Preparedstatement compared to Statement

≯℡__Kan透↙ 提交于 2020-01-01 09:33:42

问题


I was going through differences between Statement and PreparedStatement in JDBC and saw so many advantages here and here with PreparedStatement in comparison with Statement.

Some of my colleague was asking why we still need Statement and why it is not deprecated looking at the advantages of PreparedStatement.

So is there any reason why we still have the Statement in JDBC API?


回答1:


PreparedStatement is used to handle the dynamic SQL queries, where Statement is used to handle static SQL queries.




回答2:


So is there any reason why we still have the Statement in JDBC API?

Yes because it's in the SQL client-server API. If non-prepared statements were to be removed, then a feature of SQL would be missing from JDBC.

As alluded to in other answers, PreparedStatement has no advantages whatsoever if there are no dynamic parameters. For those cases it is slightly more concise to use a non-prepared statement.

Completely unrleated to those matters is the fact that PreparedStatement is a Suberinterface of Statement and so the latter cannot be removed without redesigning the API. That is more to do with the Java API though and not to do with SQL.



来源:https://stackoverflow.com/questions/31768730/are-there-any-disadvantages-using-preparedstatement-compared-to-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!