This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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: 30356
    
150

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Best place to keep the SQLs