Difference between Statement and PreparedStatement

Comparison between Statement and PreparedStatement

Difference between Statement and PreparedStatement in Tabular Form

Summary

  • The Key Difference between Statement and PreparedStatement is that Statement is used for executing simple SQL Statements whereas PreparedStatement is used for executing dynamic and pre-compiled SQL Statements.

Comparison Chart

AA Statement PreparedStatement
1 Used for executing simple SQL statements like CRUD (create, retrieve, update and delete Used for executing dynamic and pre-compiled SQL statements
2 Statement interface cannot accept parameters at run time. PreparedStatement interface accepts input parameters at runtime.
3 Statement is slower as compared to Prepared Statement PreparedStatement is faster because it is used for executing pre-compiled SQL statement
4 Statement is suitable for executing DDL commands – CREATE, drop, alter and truncate PreparedStatement is suitable for executing DML commands – SELECT, INSERT, UPDATE and DELETE
5 It is a base Interface. It is Extends statement interface.
6 Statement can not use for reading binary data. PreparedStatement used for reading binary data.
7 Statement is static PreparedStatement is dynamic.
8 Statement is usually parsed and executed each time. PreparedStatement is parsed once and executed with different parameters repeatedly.
9 Statement verifies metadata against database every time. PreparedStatement verifies metadata against the database only once.




More Difference