1. Statement :
It is used for accessing your database. Statement interface cannot accept parameters and useful when you are using static SQL statements at runtime. If you want to run SQL query only once than this interface is preferred over PreparedStatement.
Example –
//Creating The Statement Object
Statement GFG = con.createStatement();
//Executing The Statement
GFG.executeUpdate("CREATE TABLE STUDENT(ID NUMBER NOT NULL, NAME VARCHAR)"); 2. PreparedStatement :
It is used when you want to use SQL statements many times. The PreparedStatement interface accepts input parameters at runtime.
Example –
//Creating the PreparedStatement object
PreparedStatement GFG = con.prepareStatement("update STUDENT set NAME = ? where ID = ?");
//Setting values to place holders
//Assigns "RAM" to first place holder
GFG.setString(1, "RAM");
//Assigns "512" to second place holder
GFG.setInt(2, 512);
//Executing PreparedStatement
GFG.executeUpdate(); Difference between CallableStatement and PreparedStatement :
| Statement | PreparedStatement |
|---|---|
| It is used when SQL query is to be executed only once. | It is used when SQL query is to be executed multiple times. |
| You can not pass parameters at runtime. | You can pass parameters at runtime. |
| Used for CREATE, ALTER, DROP statements. | Used for the queries which are to be executed multiple times. |
| Performance is very low. | Performance is better than Statement. |
| It is base interface. | It extends statement interface. |
| Used to execute normal SQL queries. | Used to execute dynamic SQL queries. |
| We can not used statement for reading binary data. | We can used Preparedstatement for reading binary data. |
| It is used for DDL statements. | It is used for any SQL Query. |
| We can not used statement for writing binary data. | We can used Preparedstatement for writing binary data. |
| No binary protocol is used for communication. | Binary protocol is used for communication. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

