67,513
社区成员
发帖
与我相关
我的任务
分享
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL,"t3://10.135.181.106:7001");
Context ic = null;
DataSource source = null;
try {
ic = new InitialContext(env);
source = (DataSource) ic.lookup("java:comp/evn/jdbc/test");
source = (DataSource) ic.lookup("jdbc/test");
时,报错
Connection conn = null;
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, "t3://localhost:7005");
// 初始化查找命名空间
Context ctx;
try {
ctx = new InitialContext(env);
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/test");
// 获取数据库连接
conn = ds.getConnection();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
web.xml文件中配置的是
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/test</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
为什么DataSource就是取不到呢
An exception occurred: javax.naming.NameNotFoundException
// weblogic 是域控制台的用户名,weblogic123是密码
connection = source.getConnection("weblogic", "weblogic123");
connection = source.getConnection();