我正在使用包含Web服务应用程序和独立命令行应用程序的遗留WebLogic应用程序。两者都需要访问公共数据库,我想尝试让命令行应用程序使用到Web服务器的JDBC连接的池连接。 (独立的应用程序可以在服务器处于活动状态,都将在同一台物理机器上运行仅运行)使用池化JDBC连接的应用程序
我一直在试图用一个JNDI查找JDBC驱动程序如下:
try {
Context ctx = null;
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
ctx = new InitialContext(ht);
DataSource ds = (DataSource) ctx.lookup ("dbOracle");
Connection conn = null;
conn = ds.getConnection(); // <-- Exception raised here
// conn = ds.getConnection(username, password); // (Also fails)
// ...
} catch (Exception e) {
// Handle exception...
}
我已经确认JNDI名称是正确的。我可以使用其他Web应用程序连接到数据库,但我的独立应用程序仍然有困难。 - 我从WebLogic app note得到了这个想法。
关于我忽视的任何想法?
编辑1.1:我看到一个“java.lang.ClassCastException:java.lang.Object”异常。
编辑2:当我执行以下步骤:
Object dsObj = ctx.lookup("dbOracle");
System.out.println("Obj was: " + dsObj.getClass().getName());
在独立的应用程序,它报告:
"Obj was: weblogic.jdbc.common.internal._RemoteDataSource_Stub"
我试图测试相同的代码块(描述于原始问题),并能够连接到数据源(即它似乎“工作”)。该工作测试报告:
"Obj was: weblogic.jdbc.common.internal.RmiDataSource"
而且,这里有一个堆栈跟踪时,它的失败为:
####<Apr 22, 2009 10:38:21 AM EDT> <Warning> <RMI> <mlbdev16> <cgServer> <[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1240411101452> <BEA-080003> <RuntimeException thrown by rmi server: weblogic.jdbc.common.internal.RmiDataSource.getConnection()
java.lang.ClassCastException: java.lang.Object.
java.lang.ClassCastException: java.lang.Object
at weblogic.iiop.IIOPOutputStream.writeAny(IIOPOutputStream.java:1584)
at weblogic.iiop.IIOPOutputStream.writeObject(IIOPOutputStream.java:2222)
at weblogic.utils.io.ObjectStreamClass.writeFields(ObjectStreamClass.java:413)
at weblogic.corba.utils.ValueHandlerImpl.writeValueData(ValueHandlerImpl.java:235)
at weblogic.corba.utils.ValueHandlerImpl.writeValueData(ValueHandlerImpl.java:225)
at weblogic.corba.utils.ValueHandlerImpl.writeValue(ValueHandlerImpl.java:182)
at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:1957)
at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:1992)
at weblogic.iiop.IIOPOutputStream.writeObject(IIOPOutputStream.java:2253)
at weblogic.jdbc.common.internal.RmiDataSource_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:589)
at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:224)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:479)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:475)
at weblogic.rmi.internal.BasicServerRef.access$300(BasicServerRef.java:59)
at weblogic.rmi.internal.BasicServerRef$BasicExecuteRequest.run(BasicServerRef.java:1016)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:200)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:172)
如果你能告诉我们什么是例外情况,这将有所帮助。 – 2009-04-21 18:47:53
java.lang.Object不是一个例外。 – jsight 2009-04-21 18:52:28
也许尝试: 对象dsObj = ctx.lookup(“dbOracle”); System.out.println(“Obj was:”+ dsObj.getClass()。getName());看看你是否真的得到你的想法? – jsight 2009-04-21 18:53:40