java bean中连接Weblogic DataSource失败!虚心学习,焦急等待!·
rzg 2003-10-25 09:45:26 我在Weblogic7种配置Connection pool,然后添加TxDataSource,
DataSource的JNDI名称为:“petstore”.然后在一个bean中用
自定义函数获得连接。
我的代码如下:
public Connection getConnection()throws Exception {
System.out.println("Connecting to database...");
Context ctx = null;
DataSource ds = null;
try
{
ctx = new InitialContext(System.getProperties());
ds = (DataSource)ctx.lookup("petstore");
return ds.getConnection();
}
catch(Exception e)
{
System.err.println("Couldn't connect to datasource.");
e.printStackTrace();
throw new Exception(e.toString());
}
}
当调用客户端时,错误提示:
setEntityContext() called!
Connecting to database...
Couldn't connect to datasource.
javax.naming.NameNotFoundException: Unable to resolve 'petstore' Resolved: '' Un
resolved:'petstore' ; remaining name 'petstore'
at weblogic.rmi.internal.ServerRequest.sendReceive(ServerRequest.java:17
4)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke
....