Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

DataSource problem

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use WsJdbcUtil.getNativeConnection() to get the AS400 class.
 
reply
    Bookmark Topic Watch Topic
  • New Topic