There doesn’t seem to be a named query support in Spring JDBC Templates. By named query I mean the facility to reference sql statement by name in java code and keep the actual statements in some configuration file.
In the absence of out-of-box support, I’m researching the best approach to keep the sql statements outside java code.
Here are the alternatives:
- properties file
- xml properties file
- spring context xml (dependency inject)
comments?
All the approaches you’ve considered as alternative will work, yet you are adding additional layer to your design if you move the statements out of Java classes which to me is unnecessary. Consider the overhead of keeping the statements outside Java class.
If I were you, I will create a class and have the statement listed in static final. This makes it transparent, avoid unnecessary layers and makes it flexible for whoever is going to maintain your code in the future.
Example: