In my Java code, I have something like this :
ResultSet rs = statement.executeQuery(
"SELECT a,b,c FROM foo -- here starts the long query"+
" -- that is not yet finished " +
" -- that still has something to say... "+
" -- now the end !"
);
I would like to clean up my code like this :
ResultSet rs = statement.executeQuery(all_queries.getQuery("The very long one"));
I have read that ResourceBundle is for localization. So I don’t think it matches in my case.
What should all_queries be ?
EDIT :
The most important thing for me is to clean up the code.
I would put it in a file with an sql extension and implement
Querieslike:User:
Of course that’s only one way to do it. You can make
QueriesreturnStatement, or even use a dynamic proxy to mask it behind a simple Java interface (where proxy handler could create statement, set parameters and run query). Your mileage may vary.Added benefit: sql files have syntax coloring and are way easier to maintain than Strings in Java.