Possible Duplicate:
Difference between Statement and PreparedStatement
when do we go for Statement or PreparedStatement?
Possible Duplicate:
Difference between Statement and PreparedStatement
when do we go for Statement or PreparedStatement?
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.
Whenever you want to provide parameters from parameters to your SQL statement (i.e. your SQL is not a fixed string).
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.
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
create table...
(DDL statements).