aspose file tools*
The moose likes JDBC and the fly likes statement Vs prepared statement for ordinary select queries Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "statement Vs prepared statement for ordinary select queries" Watch "statement Vs prepared statement for ordinary select queries" New topic
Author

statement Vs prepared statement for ordinary select queries

sumitha sudhakar
Greenhorn

Joined: Aug 09, 2010
Posts: 21
Which is better for simple select queries statement or prepared statement?
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
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

Joined: Aug 09, 2010
Posts: 21
Thanks for the response.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30753
    
156

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: statement Vs prepared statement for ordinary select queries