This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread 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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Best place to keep the SQLs" Watch "Best place to keep the SQLs" New topic

Best place to keep the SQLs

Thilothama Green

Joined: May 13, 2004
Posts: 14

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..

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33132

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Best place to keep the SQLs
jQuery in Action, 3rd edition