Sometimes we need in our code to connect to OIM Database , we can use the Platform related methods to do this if it is plugin but in ADF codes of OIM , Platform API's doesn't support in such cases, we can use the Weblogic Data sources to get the DB Connection.
Below is the sample code for the same.
Below is the sample code for the same.
private Connection getConnectWLSDataSource(){
Connection conn=null;
try {
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
String NameProviderUrl="hostName
url";
//
Basically the URL of your OIM, better to get from a Lookup as this will change
from env to env, so better not to hard code in code
Context ctx = new InitialContext(prop);
prop.put(Context.PROVIDER_URL, NameProviderUrl);
Object obj = ctx.lookup("jdbc/ApplicationDBDS");
System.out.println("Data Source
Found");
DataSource ds = (DataSource) obj;
conn = ds.getConnection();
System.out.println("Data Source
User Name::"+conn.getMetaData().getUserName());
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
No comments:
Post a Comment