1

Possible Duplicate:
Difference between Statement and PreparedStatement

when do we go for Statement or PreparedStatement?

Cœur
  • 37,241
  • 25
  • 195
  • 267
developer
  • 9,116
  • 29
  • 91
  • 150

4 Answers4

4

you can use Statement only in case if you have no user-input parameters in your query. Otherwise, use PreparedStatement as it provides the mechanism to avoid sql-injections. Wiki is good at describing the mechanisms of it.

Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
1

Whenever you want to provide parameters from parameters to your SQL statement (i.e. your SQL is not a fixed string).

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
0

statment and preparedStatement, both used when ever you need to provise paramented or get parametes out of your dataBase using SQL. both method do the same, but preparedStatmnet will help ypu avoid sql-injections.

Adi Mor
  • 2,145
  • 5
  • 25
  • 44
0

PreparedStatement

  • If you need to pass user-provided data (to avoid SQL-injection).

  • If you run the same fixed statement a lot, for example if you need to run select * from stackoverflow_questions order by created desc limit 10 every few seconds :-) - The reason is: prepared statements are only parsed once, while statements are (at least in most databases) parsed each time.

Statement

  • For statements that don't occur a lot, such as create table... (DDL statements).
Thomas Mueller
  • 48,905
  • 14
  • 116
  • 132