File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Websphere and the fly likes DataSource problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "DataSource problem" Watch "DataSource problem" New topic
Author

DataSource problem

Marci Estreito
Greenhorn

Joined: May 03, 2005
Posts: 2
Environment:
WSAD 5.1.2
WAS 5.0.0
DB2 v.7

Web Deployment Descriptor:
<resource-ref id="ResourceRef_1115116452588">
<res-ref-name>jdbc/iSeries</res-ref-name>
<res-type>com.ibm.as400.access.AS400JDBCDataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

with WebSphere Bindings: jdbc/as400ds

Server Settings:
JDBC Provider: JTOpen AS400 DB2 JDBC Provider
DataSource: as400DS
JNDI name: jdbc/as400ds
and the properties needed for the datasource.

JAAS Authentication Alias:
defined.

Source code:

public void init() throws ServletException {

super.init();

try {
javax.naming.InitialContext jndiContext = new javax.naming.InitialContext();

javax.sql.DataSource sqlDatasource = (javax.sql.DataSource) jndiContext.lookup("java:comp/env/jdbc/iSeries");
java.sql.Connection sqlConnection = sqlDatasource.getConnection();

AS400JDBCConnection asConnection= (AS400JDBCConnection)sqlConnection;
AS400 AS400Object = asConnection.getSystem();

} catch (javax.naming.NamingException ne) {
System.out.println("init: Name not found! "+ne.getMessage());
} catch (java.lang.ClassCastException ce) {
System.out.println("init: ClassCastException: "+ce.getMessage());
} catch (SQLException se) {
System.out.println("init: SQLException: "+se.getMessage());
}
} // fim do init



Just can't cast from sql.Connection to AS400JDBCConnection.

Error:
java.lang.ClassCastException: com.ibm.ws.rsadapter.jdbc.WSJdbcConnection
at webSphereSamples.ConnPool.ServletTesteISeries.init(ServletTesteISeries.java:286 )
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doInit(StrictServletInsta nce.java:82)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._init(StrictLifecycleSer vlet.java:147)
at com.ibm.ws.webcontainer.servlet.PreInitializedServletState.init(StrictLifecycle Servlet.java:270)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.init(StrictLifecycleServ let.java:113)
at com.ibm.ws.webcontainer.servlet.ServletInstance.init(ServletInstance.java:189)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at com.ibm.ws.webcontainer.webapp.WebAppServletManager.addServlet(WebAppServletMan ager.java:870)
at com.ibm.ws.webcontainer.webapp.WebAppServletManager.loadServlet(WebAppServletMa nager.java:224)
at com.ibm.ws.webcontainer.webapp.WebAppServletManager.getServletReference(WebAppS ervletManager.java:455)
at com.ibm.ws.webcontainer.webapp.WebApp.getServletReference(WebApp.java:652)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcherInfo.calculateInfo(WebApp RequestDispatcherInfo.java:187)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcherInfo.<init>(WebAppR equestDispatcherInfo.java:68)
at com.ibm.ws.webcontainer.webapp.WebApp.getRequestDispatcher(WebApp.java:1462)
at com.ibm.ws.webcontainer.webapp.WebApp.getRequestDispatcher(WebApp.java:1421)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.ja va:268)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(Cach edInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletReques tProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.j ava:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:5 6)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:672)

When I bind the DataSource through code, works just fine.
But I must use the DataSource that was made through the server settings (WAS) that gives me this ClassCastException. I need an AS400 object, so I have to use the AS400JDBCConnection.

Any help would be appreciated.


M
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
You can use WsJdbcUtil.getNativeConnection() to get the AS400 class.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: DataSource problem