Пример #1
0
public class DBManager {
  // Constants
  private static final String RESOURCE_BUNDLE_NAME = "com.mmth.mrp.ApplicationBundle";

  // Code to get access to the resource bundle and get a value associated with a key
  private static final ResourceBundle resourceBundle =
      BundleFactory.getBundle(RESOURCE_BUNDLE_NAME);

  public DBManager() {
    super();
  }

  private static String dataSourceNonJTA;
  private static javax.naming.InitialContext ic = null;

  static {

    //    Properties props = PropertiesHelper.get(PropertiesHelper.CUSTOM_PROPERTIES_KEY);
    //                 dataSourceNonJTA="jdbc/JMRPDS_NOJTA_Server/";
    // dataSourceNonJTA="jdbc/JMRPDS_NOJTA";
    // billingposDS = props.getProperty("naming.datasource.pos");
    if (resourceBundle != null) {
      // Here, FOLLOW_UP_LABEL is the key found in the resource bundle
      dataSourceNonJTA = resourceBundle.getString("JMRPDS_NOJTA");
    }
  };

  public static Connection getNoJtaDataSource()
      throws ClassNotFoundException, SQLException, NamingException {

    InitialContext initC = getInitialContext();
    DataSource ds = (DataSource) initC.lookup(dataSourceNonJTA);

    Connection con = ds.getConnection();

    return con;
  }

  private static InitialContext getInitialContext() {

    try {

      if (ic == null) ic = new InitialContext();

    } catch (NamingException ne) {

      ne.printStackTrace();
    }

    return ic;
  }
}