Wednesday, 13 February 2019

OIM API - How to get Database Connection through Data Source Name in Standalone Code?

public Connection getDBConnection(){
    Connection conn = null;
    javax.sql.DataSource ds = null;
    Hashtable env = new Hashtable();

    env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    env.put(Context.PROVIDER_URL, "t3://<REPLACE_HOST_NAME>:14000");

    try {
          Context context = new InitialContext(env);
          ds = (javax.sql.DataSource) context.lookup("jdbc/operationsDB");
          System.out.println("Successfully looked up OIM datasource");

          if(null != ds) {
              conn = ds.getConnection();
              System.out.println("Successfully obtained OIM database connection");
          }
}catch (Exception e) {
System.out.println("Exception is : " + e.getMessage());
}
return conn;
}


No comments:

Post a Comment