Discussions

EJB programming & troubleshooting: Getting NamingException

  1. Getting NamingException (10 messages)

    Hi All,

    I am not able to get the initialcontext from websphere. I have the following environment.

    Server: WAS v6.01
    OS: Win2K
    Client: Java StandAlone Application.

    Here's the code snippet, what I am using: I would really appreciate any help in this regard.

    Thanks in Advance.
    ---------------------------------

    Properties properties = new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
    properties.put(Context.PROVIDER_URL, "iiop://localhost:9100");

    try
    {
      InitialContext jndiContext = new InitialContext(properties);
      System.out.println("Got context");

      Object ejbHome = jndiContext.lookup("StringProcessor");
      System.out.println("Got ejbHome");

      .....
    }
    catch(Exception e) {
          System.out.println(e.toString() + "\n" + e.getStackTrace());
    }

    Here's the console output:

    Got context
    javax.naming.NamingException: Failed to initialize the ORB [Root exception is java.lang.ClassCastException]

    Threaded Messages (10)

  2. Getting NamingException[ Go to top ]

    I guess you must be trying to get this context from an simple java client. I used to get a similar error. In WSAD if you are trying to do this from a simple java project you will get this error. If you are writing a client for an J2EE applicatin (ear) then try creating a client project for the J2EE application that should solve your problem.
  3. Getting NamingException[ Go to top ]

    Hello Satya,

    You are right, I used a simple java client for this; but I tried the same in jsp also. There too, I am getting an initialization exception. What should be done for the ORB initialization? Any idea..

    Thanks
    I guess you must be trying to get this context from an simple java client. I used to get a similar error. In WSAD if you are trying to do this from a simple java project you will get this error. If you are writing a client for an J2EE applicatin (ear) then try creating a client project for the J2EE application that should solve your problem.
  4. Getting NamingException[ Go to top ]

    Problem is resolved. JDK version mismatch will give this exception.

    Thanks.
    Hello Satya,You are right, I used a simple java client for this; but I tried the same in jsp also. There too, I am getting an initialization exception. What should be done for the ORB initialization? Any idea..Thanks
    I guess you must be trying to get this context from an simple java client. I used to get a similar error. In WSAD if you are trying to do this from a simple java project you will get this error. If you are writing a client for an J2EE applicatin (ear) then try creating a client project for the J2EE application that should solve your problem.
  5. Hi, I am also getting the same problem. What is that meaning of JDK Version problem. Can you pls tell me how I can resolve this.

    Thanks
    Nagesh
  6. Client JDK version should be the same as of the Websphere Server.
  7. Hi,

    I was also facing the same problem when looking up an EJB deployed on WebSphere v6 from standalone client JVM. I used IBM JDK that comes bundled with WebSphere installation for both the server and client. Could you please let me know how to resolve this.

    The exception stacktrace is follows:

    javax.naming.NamingException: Failed to initialize the ORB [Root exception is java.lang.ClassCastException]
  8. Hi

    Thanks for your help. After changed the java_home it is working for me. Now it is working for me.

    Thanks
    Nagesh
  9. Hi All,

    My application is deployed in weblogic and I want to write the Java Client which is need to acces that MBean which is deployed in weblogic. Can you please help me out in this regard.

    Thanks
    Nagesh
  10. Please help its urgent[ Go to top ]

    hi im using a stand alone java application to access a jndi data source configured on websphere 6.1 im getting the following error : failed to initialize the ORB... most of the solutions i got suggest to change from sun jdk to ibm jdk.BUT BUT how do we do that and what are the steps to be followed. Im an amateur...Please help its urgent
  11. Please help its urgent[ Go to top ]

    the code im using is given below: //WebsphereJNDI.java import java.sql.*; import java.util.*; import javax.sql.*; import javax.naming.*; import javax.rmi.*; public class WebSphereJNDI { private String websphere_server; private String jndi_datasource; private String sql_query; WebSphereJNDI(String serverpath, String jndiname, String query) { websphere_server = serverpath; jndi_datasource = jndiname; sql_query = query; } public ResultSet get_data() throws Exception { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"); env.put(Context.PROVIDER_URL, websphere_server); InitialContext ctx = new InitialContext(env); DataSource ds = (DataSource) ctx.lookup(jndi_datasource); Connection conn = ds.getConnection(); Statement stm = conn.createStatement(); ResultSet res = stm.executeQuery(sql_query); // moving cursor to first row res.next(); return res; } } // ResultSetTester.java import java.sql.*; import java.util.*; import javax.sql.*; import javax.naming.*; import javax.rmi.*; public class ResultSetTester { public static void main(String[] args) throws Exception { WebSphereJNDI test = new WebSphereJNDI( "http://hostname:port no.", "jdbc/mydatasource", "SELECT * FROM pubs.dbo.authors"); System.out.println(dump_data(test.get_data())); } public static String dump_data(java.sql.ResultSet rs) throws Exception { int rowCount = 0; String result = ""; result += "

    "; ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); // table header result += ""; for (int i = 0; i < columnCount; i++) { result += "" + rsmd.getColumnLabel(i + 1) + ""; } result += ""; // the data while (rs.next()) { rowCount++; result += ""; for (int i = 0; i < columnCount; i++) { result += "" + rs.getString(i + 1) + ""; } result += ""; } result += "

    "; return result; } }