Java中使用Weblogic配置的数据源:
DBLink link = new DBLink();
con = link.conn("chenDS");//chenDS为
System.out.println("Weblogic数据源!!");
sta = con.createStatement();
DBLink中的conn方法定义:
public Connection conn(String poolName) throws Exception {
Hashtable env = new Hashtable();
env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, "t3://localhost");
System.out.println("conn address++++++++++:" + env);
Context ctx = null;
try {
ctx = new InitialContext(env);
ds = (DataSource) ctx.lookup(poolName);
return ds.getConnection();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
--注:env里面的put方法参数是定的