• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

statement Vs prepared statement for ordinary select queries

 
sumitha sudhakar
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which is better for simple select queries statement or prepared statement?
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Statement can be used for one-time call, say to get the user details.
PreparedStatement is pre-compiled, so it can be used for queries which are repeatedly executed with different parameters.

Besides, unlike Statement, there is no chance of SQL injection with PreparedStatement.
 
sumitha sudhakar
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34860
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I always use a PreparedStatement. Almost all queries have a parameter in them and I want the security benefits. And the few queries that don't have a parameter are run multiple times.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic