Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Best place to keep the SQLs

 
Thilothama Green
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic