PreparedStatement Interface

It is a sub interface of java.sql.Statement.It is used to execute parameterized query.

Example of parameterized query:

In above statement, we are passing parameter (?) for the values. Its value will be set by calling the setter methods of PreparedStatement. By using prepareStatement() method of Connection interface, we can create PreparedStatement object.

Syntax: Important methods of PreparedStatement:
public void setInt(int paramIndex, int value) It sets integer value to the given parameter index.
public void setString(int paramIndex, String value) It sets String value to the given parameter index.
public void setFloat(int paramIndex, float value) It sets float value to the given parameter index.
public void setDouble(int paramIndex, double value) It sets double value to the given parameter index.
public int executeUpdate() It executes the query. It is used for create, drop, insert, update, delete etc.
public ResultSet executeQuery()It executes the select query. It returns an instance of ResultSet.

SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment