What are the benefits of PreparedStatement over Statement

Some of the benefits of PreparedStatement over Statement are:

  • PreparedStatement helps us in preventing SQL injection attacks because it automatically escapes the special characters.
  • PreparedStatement allows us to execute dynamic queries with parameter inputs.
  • PreparedStatement is faster than Statement. It becomes more visible when we reuse the PreparedStatement or use it’s batch processing methods for executing multiple queries.
  • PreparedStatement helps us in writing object Oriented code with setter methods whereas with Statement we have to use String Concatenation to create the query. If there are multiple parameters to set, writing Query using String concatenation looks very ugly and error prone.

你可能感兴趣的:(What are the benefits of PreparedStatement over Statement)