ClassCastException: com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource - Websphere

This is a discussion on ClassCastException: com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource - Websphere ; Hello! I am using WSAD 5.1.1 and Build in Websphere 5.1: Test Environment Server. I set up data source using different JDBC drivers for SQL 2000 and use simple java class to test Data Source Setup. Any of them does ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: ClassCastException: com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource

  1. ClassCastException: com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource

    Hello!

    I am using WSAD 5.1.1 and Build in Websphere 5.1: Test Environment
    Server.
    I set up data source using different JDBC drivers for SQL 2000 and use
    simple java class to test Data Source Setup.


    Any of them does not work to create ConnectionPoolDataSource,
    even though they work fine to create regular DataSource.

    Of Course I use different implementation class to create DataSource
    and ConnectionPoolDataSource.

    The error is:
    java.lang.ClassCastException:
    com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource that refers to the next
    line in code:
    ds = (javax.sql.ConnectionPoolDataSource)ctx.lookup("jdbc/optads");

    Thank you in advance,
    Adnrew


    WSCL0035I: Initialization of the J2EE Application Client Environment
    has completed.
    WSCL0014I: Invoking the Application Client class
    billing.ejb.clients.DSTest
    java.lang.ClassCastException:
    com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource
    at billing.ejb.clients.DSTest.main(DSTest.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:79)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:41)
    at java.lang.reflect.Method.invoke(Method.java:386)
    at com.ibm.websphere.client.applicationclient.launchC lient.createContainerAndLaunchApp(launchClient.jav a:627)
    at com.ibm.websphere.client.applicationclient.launchC lient.main(launchClient.java:422)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:79)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:41)
    at java.lang.reflect.Method.invoke(Method.java:386)
    at com.ibm.ws.bootstrap.WSLauncher.main(WSLauncher.ja va:94)


    public class DSTest
    {

    public static void main(String[] args)
    {

    InitialContext ctx = null;
    Hashtable parms = new Hashtable();
    parms.put(
    Context.INITIAL_CONTEXT_FACTORY,
    "com.ibm.websphere.naming.WsnInitialContextFactory");
    //parms.put(Context.PROVIDER_URL, "iiop:///");
    //javax.sql.DataSource ds = null;

    ConnectionPoolDataSource ds = null;

    try
    {
    ctx = new InitialContext(parms);

    ds = (javax.sql.ConnectionPoolDataSource)ctx.lookup("jdbc/optads");

    PooledConnection connP = ds.getPooledConnection("sa","sql");

    Connection conn=connP.getConnection();
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("select NumRows=count(*) from
    products");
    System.out.println("******************************");
    while (rs.next())
    {
    String col1 = rs.getString(1);
    System.out.println("The result is: " + col1);
    }
    System.out.println("******************************");

    stmt.close();
    conn.close();
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }

    }
    }

  2. Re: ClassCastException: com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource

    Andrew,
    Did you ever find a solution to this problem? I am experiencing exactly the same.
    Thanks,
    Dave

    net__space@hotmail.com (Andy) wrote in message news:...
    > Hello!
    >
    > I am using WSAD 5.1.1 and Build in Websphere 5.1: Test Environment
    > Server.
    > I set up data source using different JDBC drivers for SQL 2000 and use
    > simple java class to test Data Source Setup.
    >
    >
    > Any of them does not work to create ConnectionPoolDataSource,
    > even though they work fine to create regular DataSource.
    >
    > Of Course I use different implementation class to create DataSource
    > and ConnectionPoolDataSource.
    >
    > The error is:
    > java.lang.ClassCastException:
    > com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource that refers to the next
    > line in code:
    > ds = (javax.sql.ConnectionPoolDataSource)ctx.lookup("jdbc/optads");
    >
    > Thank you in advance,
    > Adnrew
    >


  3. Re: ClassCastException: com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource

    Dave,

    To look up a DataSource you have to add it as a resource to the bean
    calling it. This is done in ejb-jar.xml file, under the Reference tab.
    The only problem is that it does not allow you to add a resource for a
    ConnectionPoolDataSource since that is handled by the server.

    Hope this helps,
    Natalie


    davesusergroup@hotmail.com (Dave) wrote in message news:<1cf6cbc4.0401280855.50954566@posting.google.com>...
    > Andrew,
    > Did you ever find a solution to this problem? I am experiencing exactly the same.
    > Thanks,
    > Dave
    >
    > net__space@hotmail.com (Andy) wrote in message news:...
    > > Hello!
    > >
    > > I am using WSAD 5.1.1 and Build in Websphere 5.1: Test Environment
    > > Server.
    > > I set up data source using different JDBC drivers for SQL 2000 and use
    > > simple java class to test Data Source Setup.
    > >
    > >
    > > Any of them does not work to create ConnectionPoolDataSource,
    > > even though they work fine to create regular DataSource.
    > >
    > > Of Course I use different implementation class to create DataSource
    > > and ConnectionPoolDataSource.
    > >
    > > The error is:
    > > java.lang.ClassCastException:
    > > com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource that refers to the next
    > > line in code:
    > > ds = (javax.sql.ConnectionPoolDataSource)ctx.lookup("jdbc/optads");
    > >
    > > Thank you in advance,
    > > Adnrew
    > >


+ Reply to Thread