An alternate solution is to store the query in a SQL file and consume it as a Resource. Similarily to images (which we don't store as Base64 Encoded strings) we can store them externally to our Java (which we should because they aren't Java, they are SQL)
private String getTextResource(String Resource){
InputStream in = getClass().getResourceAsStream(Resource);
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line = null;
ArrayList<String> lines = new ArrayList<String>();
try {
while((line = reader.readLine()) != null){
lines.add(line);
}
} catch (IOException e) {
return null;
}
return Joiner.on("\n").join(lines);
}
public float getCurrentRiskAssessmentFactor(){
String sql = getTextResource("MyComplexSQL.sql");
return db.getQueryStatment(sql).get(0);
}
Using this technique allows you to maintain complex queries in a testable format. The sql files can be openned and tested in your favourite SQL editor, or run (independantly) against the database. This avoids transcription errors, and effort, when switching between tools.
I worked with one developer who went as far as to abstract the entire DB access so that you could only specify SQL resources, not pass in raw SQL.
Also, install Eclipse DTP. This will allow you to run the queries directly from Eclipse (or at least give you syntax highlighting).
http://www.eclipse.org/datatools/downloads.php
Optimization Tip: If you do this, it is probably advisable to use some sort of Lazy Loading/Caching mechanism for the SQL