The PreparedStatement interface belongs to the java.sql package and is used to execute parameterized SQL statements. It extends the Statement interface and allows SQL statements to be precompiled by the database. It uses the ? placeholder to represent values that are supplied later. The setXXX() methods are used to assign values to these placeholders. PreparedStatement improves performance when the same SQL statement is executed multiple times and helps protect applications against SQL injection. It is commonly used for INSERT, UPDATE, DELETE, and parameterized SELECT operations.
Methods of PreparedStatement Interface
| Methods |
|---|
|
Executes the prepared |
|
Executes the prepared |
|
Executes the prepared SQL statement and returns |
|
Sets an integer value for the specified parameter position. |
|
Sets a String value for the specified parameter position. |
|
Sets a double value for the specified parameter position. |
|
Sets a float value for the specified parameter position. |
|
Sets a long value for the specified parameter position. |
|
Sets a boolean value for the specified parameter position. |
|
ets a SQL |
|
Sets a SQL |
|
Sets a SQL |
|
Sets a SQL |
|
Sets a Java object as the value of the specified SQL parameter. |
|
Clears all parameter values that were previously set. |
|
Adds the current set of parameter values to the batch of commands. |
|
Sets a character stream as the value of the specified parameter. |
|
Sets a binary input stream as the value of the specified parameter. |
|
Closes the |
