PreparedStatement Interface

Posted By on April 29, 2016


Download PDF
ResultSet Interface
CallableStatement Interface

The Prepared Statement interface is a sub interface of Statement. It is used to execute parameterized query. The performance of the application will be faster if you use Prepared Statement interface because query is compiled only once.

Let’s see the example of parameterized query:

String sql=”insert into emp values(?,?,?)”;

The prepareStatement() method of Connection interface is used to return the object of PreparedStatement.
Syntax:

  1. public PreparedStatement prepareStatement(String query)throws SQLException{}
  2. public PreparedStatement prepareStatement(String query)throws SQLException{}

 

Methods of PreparedStatement interface:

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

 

ResultSet Interface
CallableStatement Interface

Download PDF