jQuery in Action, 2nd edition*
The moose likes Struts and the fly likes Best place to keep the SQLs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Best place to keep the SQLs" Watch "Best place to keep the SQLs" New topic
Author

Best place to keep the SQLs

Thilothama Green
Greenhorn

Joined: May 13, 2004
Posts: 14
Hi,

In a web based application, with simple architecture like

Struts - Transfer Objects - Business Tier,

Which is the best way to keep SQLs?

1. In Interface?
2. In properties file?

And also please include Disadv and Adv of each approach. If any other approach is there, please explain that too..

But not middlewares like Hibernate or whatever..

Thanks
Thilothama
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30050
    
149

Thilothama,
The best place is in a property file because the SQL can change independently of the code to some extent. For example, the schema name could change.

If you are sure the SQL will not change after deployment, an interface is next best. The interface should only contain constants and be referenced as MyInterface.QUERY_NAME rather than implementing the interface.

The other choice is to store the queries in the class that does the data processing. This keeps the query with the parameter setting and result set processing code.


[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
 
Don't get me started about those stupid light bulbs.
 
subject: Best place to keep the SQLs
 
Similar Threads
SQL trace logs
Servlets and PropertyResourceBundle
sql doubt
CMP vs BMP
Problem in Initializing SessionFactory