View Javadoc

1   package org.paneris.jal.model;
2   
3   import java.sql.ResultSet;
4   import java.sql.Statement;
5   import java.sql.Connection;
6   
7   /**
8   * <p>A wrapper to allow easy access to system properties.</p>
9   *
10  **/
11  
12  public class SystemProperties {
13  
14      private DBConnectionManager connMgr;
15      private String database;
16  
17  
18  /**
19   * Constructor
20   **/
21      public SystemProperties(String db) throws Exception {
22          database = db;
23      }
24  
25      public String getProperty(String property) throws Exception {
26          String sqlString = "SELECT * FROM datadictionaryproperties WHERE TRIM(propertyname) = '" + property + "'";
27          String propertyValue = "";
28          connMgr = DBConnectionManager.getInstance();
29          try {
30              Connection conn = connMgr.getConnection("SystemProperties",database);
31              Statement s = conn.createStatement();
32              ResultSet rs = s.executeQuery(sqlString);
33              if (rs.next()) {
34                  propertyValue = rs.getString("propertyvalue").trim();
35              } else {
36                  connMgr.freeConnection(database, conn);
37                  throw new Exception("Failed to find property: " + property);
38              }
39              connMgr.freeConnection(database, conn);
40              return propertyValue;
41          } catch (Exception e) {
42              throw new Exception(e.toString() + " getProperty SQL: " + sqlString);
43          }
44      }
45  }