Topic
  • 6 replies
  • Latest Post - ‏2006-12-06T16:56:01Z by SystemAdmin
SystemAdmin
SystemAdmin
1215 Posts

Pinned topic Exception in Looking up DataSource in WAS 5.1

‏2004-06-10T06:46:41Z |
Hi,
I am getting the some Exception when i tried to connect Oracle Data Source through JNDi which is binded to JNDI Server in WAS. I am running from Websphere Studio Application Developer 5.1.2.

plz see the Program

package com.lessly.j2eeclient;
import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

/*
* Created on Jun 1, 2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/

/**
* @author lessly
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class TestClient {

public static void main(String[] args) {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.PROVIDER_URL, "corbaloc:iiop:localhost:2809");
Context initialContext = null;
try {
initialContext = new InitialContext(env);

DataSource specificDataSource =
(DataSource) javax.rmi.PortableRemoteObject.narrow(initialContext.lookup("jdbc/testdb"), DataSource.class);
System.out.println(" Class is : " + initialContext.lookup("jdbc/testdb").getClass().toString());
/*Connection con = ds.getConnection();
Statement st = con.createStatement();
ResultSet res = st.executeQuery("select sysdate from dual");
while(res.next()){
System.out.println("Today Date is : " + res.getString(1));
}
res.close();
st.close();
con.close();*/
} catch (Exception e) {
e.printStackTrace();
}
}
}
The Exception is :

java.lang.ClassNotFoundException: com.ibm.ejs.jts.jts.CurrentSet
at java.net.URLClassLoader.findClass(URLClassLoader.java:241)
at java.lang.ClassLoader.loadClass(ClassLoader.java:516)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:460)
at java.lang.ClassLoader.loadClass(ClassLoader.java:448)
at com.ibm.ws.util.ImplFactory.loadClassFromKey(ImplFactory.java:111)
at com.ibm.ejs.jts.jts.CurrentFactory.<clinit>(CurrentFactory.java:56)
at com.ibm.ws.naming.jndicos.CNContextImpl.suspendTransaction(CNContextImpl.java:4064)
at com.ibm.ws.naming.jndicos.CNContextImpl.cosResolve(CNContextImpl.java:3521)
at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1565)
at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1525)
at com.ibm.ws.naming.jndicos.CNContextImpl.lookup(CNContextImpl.java:1225)
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:132)
at javax.naming.InitialContext.lookup(InitialContext.java:359)
at com.lessly.j2eeclient.TestClient.main(TestClient.java:35)
java.lang.ClassCastException: javax.naming.Reference
at com.ibm.rmi.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:366)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:146)
at com.lessly.j2eeclient.TestClient.main(TestClient.java:35)
Updated on 2006-12-06T16:56:01Z at 2006-12-06T16:56:01Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: Exception in Looking up DataSource in WAS 5.1

    ‏2005-10-19T18:38:57Z  
    hi.. tell me whether you are trying to execute this program through your web project or java project.. if it is java project, there are some issues which even i try to solve...

    if it is web project, you can create an alias name for jndi through web.xml.. then try again, it should work..

    if you find solution for java project, mail me back to srmselva@yahoo.com or post the message here...

    thanks
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: Exception in Looking up DataSource in WAS 5.1

    ‏2005-12-09T22:58:35Z  
    Guys,

    I am also facing same the problem.
    Got the Initial context, but getting java.lang.ClassCastException: javax.naming.Reference on casting it to DataSource.

    Getting the same problem on usage of PortableRemoteObject.narrow(..)

    Please, kindly forward the solution.

    Code snippet -

    Hashtable properties = new Hashtable(2);
    properties.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
    properties.put(Context.PROVIDER_URL, "corbaloc:iiop:fswasbox1:2809");
    javax.naming.InitialContext initContext = new javax.naming.InitialContext(properties);
    ds= (javax.sql.DataSource)initContext.lookup(datasourceName);

    //Object ds_obj = initContext.lookup(datasourceName);
    //ds = (javax.sql.DataSource) javax.rmi.PortableRemoteObject.narrow(ds_obj, DataSource.class);
    Thanks & Regards,
    ~ Subba Reddy
    Email: m_subbareddy@hotmail.com
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: Exception in Looking up DataSource in WAS 5.1

    ‏2006-02-06T19:50:47Z  
    Guys,

    I am also facing same the problem.
    Got the Initial context, but getting java.lang.ClassCastException: javax.naming.Reference on casting it to DataSource.

    Getting the same problem on usage of PortableRemoteObject.narrow(..)

    Please, kindly forward the solution.

    Code snippet -

    Hashtable properties = new Hashtable(2);
    properties.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
    properties.put(Context.PROVIDER_URL, "corbaloc:iiop:fswasbox1:2809");
    javax.naming.InitialContext initContext = new javax.naming.InitialContext(properties);
    ds= (javax.sql.DataSource)initContext.lookup(datasourceName);

    //Object ds_obj = initContext.lookup(datasourceName);
    //ds = (javax.sql.DataSource) javax.rmi.PortableRemoteObject.narrow(ds_obj, DataSource.class);
    Thanks & Regards,
    ~ Subba Reddy
    Email: m_subbareddy@hotmail.com
    I also ran into a problem with casting a datasource in WAS.

    My WAS environment is jdk 1.3 thus that's the version of the Oracle driver I downloaded. But when I had the classes12 included in my project I found that the driver included the javax.sql interfaces. (Because it they didn't come into play until jdk 1.4) The J2EE does include them so when I'd try to cast, I'd be trying to cast a Datasource that was loaded in a different class loader than what my app was running where it also found a javax.sql.DataSource in the module. So I went ahead and removed those classes from the driver and thus eliminated the problem. My only other options I knew of where to either not include the jar in my project or run Parent First. Neither where options my project desired.

    I see it's been a couple months so you've probably already worked through your problems, but who knows maybe this will help someone.
  • sunildumpala
    sunildumpala
    1 Post

    Re: Exception in Looking up DataSource in WAS 5.1

    ‏2006-05-05T07:14:51Z  
    I also ran into a problem with casting a datasource in WAS.

    My WAS environment is jdk 1.3 thus that's the version of the Oracle driver I downloaded. But when I had the classes12 included in my project I found that the driver included the javax.sql interfaces. (Because it they didn't come into play until jdk 1.4) The J2EE does include them so when I'd try to cast, I'd be trying to cast a Datasource that was loaded in a different class loader than what my app was running where it also found a javax.sql.DataSource in the module. So I went ahead and removed those classes from the driver and thus eliminated the problem. My only other options I knew of where to either not include the jar in my project or run Parent First. Neither where options my project desired.

    I see it's been a couple months so you've probably already worked through your problems, but who knows maybe this will help someone.
    Hi There. I am also running into the same issue. I am using WSAD 5.1 (and I am new to it) I have created a datasource and I am trying to access it through a simple Java application as follows
    public class HelloWorld {
    public static void main(String args[]){
    System.out.println("Hello World");
    try
    {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
    InitialContext ctx = new InitialContext(env);
    System.out.println("InitialContext success" + ctx);
    Object obj = (Object)ctx.lookup("jdbc/ds1");

    DataSource ds = (DataSource)obj;

    I am getting a classCastException because the object I am getting is not a datasource but a Reference

    Could you please explain a bit more in detail how you fixed the issue.

    Thanks,
    Sunil
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: Exception in Looking up DataSource in WAS 5.1

    ‏2006-05-05T14:14:42Z  
    Hi There. I am also running into the same issue. I am using WSAD 5.1 (and I am new to it) I have created a datasource and I am trying to access it through a simple Java application as follows
    public class HelloWorld {
    public static void main(String args[]){
    System.out.println("Hello World");
    try
    {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
    InitialContext ctx = new InitialContext(env);
    System.out.println("InitialContext success" + ctx);
    Object obj = (Object)ctx.lookup("jdbc/ds1");

    DataSource ds = (DataSource)obj;

    I am getting a classCastException because the object I am getting is not a datasource but a Reference

    Could you please explain a bit more in detail how you fixed the issue.

    Thanks,
    Sunil
    My apologies, but I don't think my issue was the same what you've got going on. I was getting a DataSource, just not from the desired classloader. I probably should have posted that info on another thread or different branch or something.
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: Exception in Looking up DataSource in WAS 5.1

    ‏2006-12-06T16:56:01Z  
    Hi There. I am also running into the same issue. I am using WSAD 5.1 (and I am new to it) I have created a datasource and I am trying to access it through a simple Java application as follows
    public class HelloWorld {
    public static void main(String args[]){
    System.out.println("Hello World");
    try
    {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
    InitialContext ctx = new InitialContext(env);
    System.out.println("InitialContext success" + ctx);
    Object obj = (Object)ctx.lookup("jdbc/ds1");

    DataSource ds = (DataSource)obj;

    I am getting a classCastException because the object I am getting is not a datasource but a Reference

    Could you please explain a bit more in detail how you fixed the issue.

    Thanks,
    Sunil
    > Hi There. I am also running into the same issue. I am
    > using WSAD 5.1 (and I am new to it) I have created a
    > datasource and I am trying to access it through a
    > simple Java application as follows
    > public class HelloWorld {
    > public static void main(String args[]){
    > System.out.println("Hello World");
    > try
    > {
    > Hashtable env = new Hashtable();
    > env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.web
    > sphere.naming.WsnInitialContextFactory");
    > InitialContext ctx = new InitialContext(env);
    > System.out.println("InitialContext success" + ctx);
    > Object obj = (Object)ctx.lookup("jdbc/ds1");
    >
    > DataSource ds = (DataSource)obj;
    >
    >
    >
    > I am getting a classCastException because the object
    > I am getting is not a datasource but a Reference
    >
    > Could you please explain a bit more in detail how you
    > fixed the issue.
    >
    > Thanks,
    > Sunil

    Hi Sunil,

    I am also facing the same issue.
    Were you able to solve the problem?
    Can you please let me know the solution?

    Thanks
    Bablu