PreparedStatement interface in JDBC | JDBC Tutorials -Java

These JDBC Tutorials “PreparedStatement interface in JDBC” post explains clearly what is static query or parameter query and how to execute static queries using using PreparedStatement interface in jdbc applications.



  • PreparedStatement is an interface.
  • It is an extension of Statement interface.
  • PreparedStatement in static, hence we need to prepare the statement without values.
  • It is used to execute parameterized static query.
  • The performance of the application will be faster if you use PreparedStatement interface because query is compiled only once.


  • for example…..
              String query = “insert into online_student values(?,?,?)”;
  • Here ‘?’ is working like a variable by which we can pass parameter.
  • Passed value will be set by calling the setter methods of PreparedStatement.



  1. void setInt(int, int) : Sets the integer value to the given parameter index.
  2. void setString(int, String) : Sets the String value to the given parameter index.
  3. void setFloat(int, float) : Sets the float value to the given parameter index.
  4. void setDouble(int, double) : Sets the double value to the given parameter index.
  5. int executeUpdate() : Executes the query. It is used for create, drop, insert, update, delete etc.
  6. ResultSet executeQuery() : Executes the select query. It returns an instance of ResultSet.
Share this