Hi,
I've got a webapp running on a Websphere 6.1 Server which JNDI lookups for a datasource. This webapp runs fine, the Websphere server recognizes the datasource ref in the web.xml etc..
Now we added a second webapp which should use this datasource with same configuration but
I recieve a ClassCastException
when I try to access the datasource.
To locate the problem I've put this into my code
try{
InitialContext ctx = new InitialContext();
Object obj = ctx.lookup(N2WebConstants.datasourceJNDI);
System.err.println(obj.toString());
System.err.println(obj.getClass());
con = ((DataSource) obj).getConnection();
}catch (Exception e){
System.err.println(e);
System.err.println(e.getCause());
}
In the error log this is printed
[5/10/10 9:45:13:531 CEST] 00000176 SystemErr R com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource@e9240c0
[5/10/10 9:45:13:532 CEST] 00000176 SystemErr R class com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource
[5/10/10 9:45:13:539 CEST] 00000176 SystemErr R java.lang.ClassCastException
at java.lang.Throwable.<init>(Throwable.java:181)
at java.lang.Exception.<init>(Exception.java:29)
at java.lang.RuntimeException.<init>(RuntimeException.java:32)
at java.lang.ClassCastException.<init>(ClassCastException.java:29)
at de.ac.action.MAction.execute(MAction.java:77)
at de.ac.web.GetTheView.doService(GetTheView.java:88)
at de.ac.web.GetTheView.doGet(GetTheView.java:60)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1096)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:570)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3444)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:267)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:815)
at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1466)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:119)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:458)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:387)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:267)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:556)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:583)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:979)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1064)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1462)
[5/10/10 9:45:13:539 CEST] 00000176 SystemErr R null
So, I get a Object of Class com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource
but casting DataSource
causes the ClassCastException
?
I tried this app on another server, WAS 6.1 fresh install, there it works. It also works in a tomcat env.
One more important thing: It is a DB2 datasource which uses the jt400.jar
- there are some simliar problems with the Oracle JDBC driver and WAS 6.
Maybe one of you has some suggestions?