我正在尝试通过eclipse连接到我的websphere 7.0服务器中可用的数据源。
以下是代码。
Hashtable<String, String> pdEnv = new Hashtable<String, String>();
pdEnv.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
pdEnv.put(Context.PROVIDER_URL, "iiop://XX.XXX.XX.XX:YYYY");
Connection connection =null;
Context initialContext = new InitialContext(pdEnv);
DataSource datasource = (DataSource) initialContext.lookup("jdbc/AEDS");
if (datasource != null) {
connection = datasource.getConnection("admin","admin"); // DB credintials
} else {
System.out.println("hi");
}
但我在尝试连接时遇到以下异常
Exception in thread "P=365798:O=0:CT" javax.naming.ServiceUnavailableException: A communication failure occurred while attempting to obtain an initial context with the provider URL:
at com.ibm.ws.naming.util.WsnInitCtxFactory.mapInitialReferenceFailure(WsnInitCtxFactory.java:2271)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getWsnNameService(WsnInitCtxFactory.java:1457)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootContextFromServer(WsnInitCtxFactory.java:987)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootJndiContext(WsnInitCtxFactory.java:909)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:581)
我也对与iiop url一起使用的端口号感到困惑,因为我们在同一节点上运行多个服务器,每个服务器都有不同的bootstrap端口。