Displaying differences for changeset
 
display as  

src/java/m/wqm/thresholdscores/V1_0.java

@@ -28,9 +28,6 @@
 
 public class V1_0 extends ModelDataService {
 
-    private Connection conn;
-    private Statement statement;
-
     private String error_msg;
 
     ArrayList<V1_0.Input> components; // store the set of all input soilcomponents as objects
@@ -39,8 +36,6 @@
     @Override
     // reading the inputs from the json file into input object and placing it in the arraylist
     protected void preProcess() throws Exception {
-        this.conn = null;
-        this.statement = null;
         this.components = new ArrayList<>();
         this.result1 = new ArrayList<>();
         this.error_msg = "";
@@ -71,9 +66,9 @@
     @Override
     protected String process() throws Exception {
         if (this.error_msg.isEmpty()) {
-            try {
-                conn = wqm.utils.WQMTools.getConnection("wqm", LOG);
-                statement = conn.createStatement();
+            try (
+                    Connection conn = wqm.utils.WQMTools.getConnection("wqm", LOG);
+                    Statement statement = conn.createStatement();) {
 
                 for (V1_0.Input ip : components) {
                     String query = "SELECT threshold_treatment_score FROM wqm_threshold_scores WHERE wqm_concern=" + "'" + "Nitrogen in Ground Water" + "'" + "AND hazard_loss_rating ='" + ip.aoa_nslp + "' AND treatment_level='" + ip.aoa_treatment_level + "';";
@@ -154,16 +149,6 @@
             } catch (ServiceException | SQLException ex) {
                 this.error_msg = "Cannot process that request: " + ex.getMessage();
                 LOG.log(Level.SEVERE, this.error_msg);
-            } finally {
-                if (this.statement != null) {
-                    this.statement.close();
-                    this.statement = null;
-                }
-
-                if (this.conn != null) {
-                    this.conn.close();
-                    this.conn = null;
-                }
             }
         }