Let's think about moving sql out of java in order to make queries easier to read and allow for alternate queries according to database
A good first step I think would be to use QueryLoader and put the sql in a properties file. Maybe we could put our own query loader in org-srs-datahandling-common.
http://commons.apache.org/dbutils/apidocs/org/apache/commons/dbutils/QueryLoader.html
Example of use:
Code Block |
---|
|
sqlstatement=\
select someid, someproperty from sometable where someid = ?
sqlstatementtrue=\
select someid from sometable\
where someproperty = ?
|
Code Block |
---|
title | MyClass.java |
---|
borderStyle | solid |
---|
|
final Map queryMap;
public MyClass(){
queryMap = QueryLoader.instance().load("/org/srs/project/sql.properties");
}
void someMethod(){
Connection connection = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try{
connection = Utils.getConnection();
stmt = connection.prepareStatement(queryMap.get("sqlstatement"));
stmt.setLong(1,1234);
rs = stmt.executeQuery();
if(rs.next()){
System.out.println(rs.getString(2);
}
catch (Exception e){
System.out.println("Some error happened");
}
};
|