@@ -33,8 +33,6 @@ |
int psolsurf_ipm_score = 0; |
int padsurf_ipm_score = 0; |
int pdrift_ipm_score = 0; |
- private Connection conn; |
- private Statement statement; |
|
//JSONArray getArray |
ArrayList<V1_0.Input> components = new ArrayList<>(); // store the set of all input soilcomponents as objects |
@@ -44,8 +42,6 @@ |
// reading the inputs from the json file into input object and placing it in the arraylist |
protected void preProcess() throws Exception { |
JSONArray groups = getJSONArrayParam("pestcomponents"); |
- this.conn = null; |
- this.statement = null; |
for (int i = 0; i < groups.length(); i++) { |
Map<String, JSONObject> group = JSONUtils.preprocess(groups.getJSONArray(i)); |
int AoAId = JSONUtils.getIntParam(group, "AoAId", 0); |
@@ -56,10 +52,10 @@ |
|
@Override |
protected String process() throws Exception { |
- try { |
- conn = wqm.utils.WQMTools.getConnection("wqm", LOG); |
+ try ( |
+ Connection conn = wqm.utils.WQMTools.getConnection("wqm", LOG); |
+ Statement statement = conn.createStatement();) { |
conn.setAutoCommit(false); |
- statement = conn.createStatement(); |
for (V1_0.Input ip : components) { |
String query = "SELECT ipm_mitigation_score FROM wqm_ipm_scores WHERE ipm_level='" + ip.plan_ipm_level + "' AND wqm_concern='Pesticide Leaching'"; |
ResultSet results = statement.executeQuery(query); |
@@ -86,16 +82,8 @@ |
} catch (SQLException se) { |
LOG.info("Did not open database for WQM-17!"); |
LOG.info(se.getMessage()); |
- } finally { |
- if (this.statement != null) { |
- this.statement.close(); |
- this.statement = null; |
- } |
- if (this.conn != null) { |
- this.conn.close(); |
- this.conn = null; |
- } |
- } |
+ } |
+ |
return EXEC_OK; |
} |
|