I’m working with a legacy WebLogic application that contains a web-service application and a standalone, command-line application. Both need access to a common database and I would like to try and get the command-line application use a pooled connection to the web-server’s JDBC connection. (The standalone application can only be run when the server is active and both will be run on the same physical machine.)
I’ve been trying to use a JNDI lookup to the JDBC driver as follows:
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... }
I’ve confirmed the JNDI name is correct. I am able to connect to the database with other web-applications but my standalone application continues to have difficulties. – I got the idea for this from a WebLogic app note.
Any ideas on what I have overlooked?
EDIT 1.1: I’m seeing a ‘java.lang.ClassCastException: java.lang.Object’ exception.
EDIT 2: When I perform the following:
Object dsObj = ctx.lookup('dbOracle'); System.out.println('Obj was: ' + dsObj.getClass().getName());
In the standalone-application, it reports:
'Obj was: weblogic.jdbc.common.internal._RemoteDataSource_Stub'
I attempted to test the same chunk of code (described in original question) in the web-application and was able to connect to the datasource (i.e. it seems to ‘work’). This working test reports:
'Obj was: weblogic.jdbc.common.internal.RmiDataSource'
Also, here’s a stack-trace for when it’s failing:
####<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)
This exception looks like it is generated on the server side. The first thing I would do is verify the version of WebLogic Server and check the classpath of the client application. You need to make sure your client app has the same version of the WebLogic client jar files as the WebLogic Server. You are including weblogic client jar files in the classpath of your client, right? Since your are using WebLogic’s RMI driver, I don’t believe you need any Oracle jar files in the classpath of the client. Your client is essentially speaking RMI to the WebLogic Server. The WebLogic Server connection pool you configured knows how to speak to Oracle. It shouldn’t matter what JDBC driver you use in your connection pool.