13 Replies Latest reply on Sep 30, 2005 12:44 AM by zhjjava

    javax.naming.NameNotFoundException: OracleDS not bound

    mukundjaiswal

      hi,

      i would really appreciate if anyone can halp me out with this

      i am encountering exceptions


      javax.naming.NameNotFoundException: CMPOracleDS not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:282)
      at sun.reflect.GeneratedMethodAccessor62.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
      at sun.rmi.transport.Transport$1.run(Transport.java:153)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
      at java.lang.Thread.run(Thread.java:595)
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
      at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:530)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:509)
      at javax.naming.InitialContext.lookup(InitialContext.java:351)
      at SenderClass.JMSQueueMessageProducer.establishConnection(JMSQueueMessageProducer.java:77)
      at SenderClass.JMSQueueMessageProducer.main(JMSQueueMessageProducer.java:147)


      my oracle-ds.xml entries are :

      <?xml version="1.0" encoding="UTF-8"?>

      <!-- ===================================================================== -->
      <!-- -->
      <!-- JBoss Server Configuration -->
      <!-- -->
      <!-- ===================================================================== -->


      <local-tx-datasource>
      <jndi-name>OracleDS</jndi-name>
      <connection-url>jdbc:oracle:thin:@3.220.220.220:1521:ora9idev</connection-url>
      <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
      <user-name>mukund</user-name>
      mukund

      <min-pool-size>5</min-pool-size>
      <max-pool-size>100</max-pool-size>

      <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>


      <type-mapping>Oracle9i</type-mapping>


      </local-tx-datasource>



      The code through which i am excessing it is
      private static InitialContext jc = null;
      /**
      * DOCUMENT ME!
      */
      public static void establishConnection() {
      try {

      jc = new InitialContext();

      System.out.println("not yet connected 1");

      javax.sql.DataSource ds = (javax.sql.DataSource) jc.lookup("java:/CMPOracleDS");
      Connection conn = ds.getConnection();

      if (conn != null) {
      System.out.println("connected:" + conn.getMetaData().getUserName());
      }

      } catch (Exception e) {
      e.printStackTrace();
      }
      }

      the JNDI properties filein is the src folder and contians the following entries
      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
      java.naming.provider.url=localhost

      i tried searching alot but could not make it work properly with JBOSS 3.2.5.

      i have tried using help available on jboss and oracle site.

      can anyone guide/ help me in setting up the connection with oracle 9i db
      thanks & regards,
      Mukund

        • 1. Re: javax.naming.NameNotFoundException: OracleDS not bound
          mukundjaiswal

          there was a mistake in the lookup:

          javax.sql.DataSource ds = (javax.sql.DataSource) jc.lookup("java:/OracleDS");

          Help awaited,
          thanks & regards,

          Mukund

          • 2. Re: javax.naming.NameNotFoundException: OracleDS not bound
            darranl

            The JNDI name of the lookup does not match the JNDI name in the descriptor.

            <jndi-name>OracleDS</jndi-name>


            You need to lookup: -

            javax.sql.DataSource ds = (javax.sql.DataSource) jc.lookup("java:/OracleDS");


            However you can only perform the lookup from code running within JBoss, in JBoss 3.2.5 you can not get remote access to a datasource.



            • 3. Re: javax.naming.NameNotFoundException: OracleDS not bound
              darranl

              That also means you have not posted the correct stack trace as the stack trace is for the original code.

              • 4. Re: javax.naming.NameNotFoundException: OracleDS not bound
                mukundjaiswal

                sorry guys two more mistakes

                first in the begining line of exceptions encountered. the datasource name is OracleDS

                javax.naming.NameNotFoundException: OracleDS not bound

                second in the oracle-ds.xml

                <pass word>mukund</pass word> instead of just mukund after <user-name> tag

                please pardon the typos
                Help awaited....Mukund

                • 5. Re: javax.naming.NameNotFoundException: OracleDS not bound
                  darranl

                  Where is your code running? In JBoss or stand-alone?

                  Go to the JMX console http://localhost:8080/jmx-console find the JNDI View MBean and invoke the list operation. Can you see if your datasource is bound?

                  • 6. Re: javax.naming.NameNotFoundException: OracleDS not bound
                    mukundjaiswal

                    hi darranel,

                    thanks for reply

                    i am reframing the whoe scenario

                    the JNDI in the lookup matched the JNDI name in the descriptor

                    i am encountering exceptions

                    javax.naming.NameNotFoundException: OracleDS not bound
                    at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
                    at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
                    at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
                    at org.jnp.server.NamingServer.lookup(NamingServer.java:282)
                    at sun.reflect.GeneratedMethodAccessor62.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                    at java.lang.reflect.Method.invoke(Method.java:585)
                    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
                    at sun.rmi.transport.Transport$1.run(Transport.java:153)
                    at java.security.AccessController.doPrivileged(Native Method)
                    at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
                    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
                    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
                    at java.lang.Thread.run(Thread.java:595)
                    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
                    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
                    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
                    at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
                    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:530)
                    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:509)
                    at javax.naming.InitialContext.lookup(InitialContext.java:351)
                    at SenderClass.JMSQueueMessageProducer.establishConnection(JMSQueueMessageProducer.java:77)
                    at SenderClass.JMSQueueMessageProducer.main(JMSQueueMessageProducer.java:147)


                    my oracle-ds.xml entries are :

                    <?xml version="1.0" encoding="UTF-8"?>

                    <!-- ===================================================================== -->
                    <!-- -->
                    <!-- JBoss Server Configuration -->
                    <!-- -->
                    <!-- ===================================================================== -->


                    <local-tx-datasource>
                    <jndi-name>OracleDS</jndi-name>
                    <connection-url>jdbc:oracle:thin:@3.220.220.220:1521:ora9idev</connection-url>
                    <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
                    <user-name>mukund</user-name>
                    <!--the tag is not coming int he preview therefore i have inserted the space. it is nto there in the actuall oracle-ds.xml -->
                    <pass word>windrmd</pass word>
                    <min-pool-size>5</min-pool-size>
                    <max-pool-size>100</max-pool-size>
                    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>

                    <!--the tag is not coming int he preview therefore i have inserted the space. it is nto there in the actuall oracle-ds.xml -->
                    <meta data>
                    <type-mapping>Oracle9i</type-mapping>
                    </meta data>


                    </local-tx-datasource>


                    The code through which i am excessing it is

                    private static InitialContext jc = null;
                    /**
                    * DOCUMENT ME!
                    */
                    public static void establishConnection() {
                    try {

                    jc = new InitialContext();

                    System.out.println("not yet connected 1");

                    javax.sql.DataSource ds = (javax.sql.DataSource) jc.lookup("java:/OracleDS");
                    Connection conn = ds.getConnection();

                    if (conn != null) {
                    System.out.println("connected:" + conn.getMetaData().getUserName());
                    }

                    } catch (Exception e) {
                    e.printStackTrace();
                    }
                    }


                    the JNDI properties filein is the src folder and contians the following entries

                    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
                    java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
                    java.naming.provider.url=localhost


                    i tried searching alot but could not make it work properly with JBOSS 3.2.5.

                    i have tried using help available on jboss and oracle site.

                    can anyone guide/ help me in setting up the connection with oracle 9i db
                    thanks & regards,
                    Mukund

                    • 7. Re: javax.naming.NameNotFoundException: OracleDS not bound
                      darranl

                      Where is your code running, is it a component within JBoss or is it a stand alone application?

                      • 8. Re: javax.naming.NameNotFoundException: OracleDS not bound
                        mukundjaiswal

                        the application is a ejb project. i deploy the project on the server and then start the server and then run the java file which contains the main
                        inside the main i am making a call to the establishConnection() method.

                        • 9. Re: javax.naming.NameNotFoundException: OracleDS not bound
                          darranl

                          If you are calling the 'establishConnection' method directly from a main method this means your code is running stand alone and is connecting to the server remotely.

                          Using JBoss 3.2.5 you can not get remote access to datasources.

                          This feature was added to the JBoss 4 series but is not recomended.

                          • 10. Re: javax.naming.NameNotFoundException: OracleDS not bound
                            mukundjaiswal

                            hi

                            sending across the console output
                            it show sthat the connection is bounded

                            18:01:37,141 INFO [Server] Starting JBoss (MX MicroKernel)...
                            18:01:37,141 INFO [Server] Release ID: JBoss [WonderLand] 3.2.5 (build: CVSTag=JBoss_3_2_5 date=200406251954)
                            18:01:37,141 INFO [Server] Home Dir: C:\jboss-3.2.5
                            18:01:37,141 INFO [Server] Home URL: file:/C:/jboss-3.2.5/
                            18:01:37,141 INFO [Server] Library URL: file:/C:/jboss-3.2.5/lib/
                            18:01:37,141 INFO [Server] Patch URL: null
                            18:01:37,141 INFO [Server] Server Name: myserver
                            18:01:37,141 INFO [Server] Server Home Dir: C:\jboss-3.2.5\server\myserver
                            18:01:37,141 INFO [Server] Server Home URL: file:/C:/jboss-3.2.5/server/myserver/
                            18:01:37,141 INFO [Server] Server Data Dir: C:\jboss-3.2.5\server\myserver\data
                            18:01:37,157 INFO [Server] Server Temp Dir: C:\jboss-3.2.5\server\myserver\tmp
                            18:01:37,157 INFO [Server] Server Config URL: file:/C:/jboss-3.2.5/server/myserver/conf/
                            18:01:37,157 INFO [Server] Server Library URL: file:/C:/jboss-3.2.5/server/myserver/lib/
                            18:01:37,157 INFO [Server] Root Deployment Filename: jboss-service.xml
                            18:01:37,172 INFO [Server] Starting General Purpose Architecture (GPA)...
                            18:01:37,750 INFO [ServerInfo] Java version: 1.5.0_04,Sun Microsystems Inc.
                            18:01:37,750 INFO [ServerInfo] Java VM: Java HotSpot(TM) Client VM 1.5.0_04-b05,Sun Microsystems Inc.
                            18:01:37,750 INFO [ServerInfo] OS-System: Windows XP 5.1,x86
                            18:01:38,485 INFO [Server] Core system initialized
                            18:01:44,141 INFO [Log4jService$URLWatchTimerTask] Configuring from URL: resource:log4j.xml
                            18:01:44,797 INFO [WebService] Using RMI server codebase: http://mukund:8083/
                            18:01:45,157 INFO [NamingService] Started jnpPort=1099, rmiPort=1098, backlog=50, bindAddress=/0.0.0.0, Client SocketFactory=null, Server SocketFactory=org.jboss.net.sockets.DefaultSocketFactory@ad093076
                            18:01:55,078 INFO [RARMetaData] Loading JBoss Resource Adapter for JDBC 2 XA drivers
                            18:01:55,094 INFO [RARMetaData] Required license terms present. See deployment descriptor.
                            18:02:02,328 INFO [MailService] Mail Service bound to java:/Mail
                            18:02:03,891 INFO [Embedded] Catalina naming disabled
                            18:02:05,500 INFO [Http11Protocol] Initializing Coyote HTTP/1.1 on http-0.0.0.0-8080
                            18:02:05,578 INFO [Catalina] Initialization processed in 1515 ms
                            18:02:05,578 INFO [StandardService] Starting service jboss.web
                            18:02:05,610 INFO [StandardEngine] Starting Servlet Engine: Apache Tomcat/5.0.26
                            18:02:05,672 INFO [StandardHost] XML validation disabled
                            18:02:05,766 INFO [Catalina] Server startup in 188 ms
                            18:02:05,969 WARN [DeploymentInfo] Only the root deployment can set the loader repository, ingoring config=null
                            18:02:06,047 INFO [TomcatDeployer] deploy, ctxPath=/invoker, warUrl=file:/C:/jboss-3.2.5/server/myserver/deploy/http-invoker.sar/invoker.war/
                            18:02:08,860 WARN [DeploymentInfo] Only the root deployment can set the loader repository, ingoring config=null
                            18:02:08,875 INFO [TomcatDeployer] deploy, ctxPath=, warUrl=file:/C:/jboss-3.2.5/server/myserver/deploy/jbossweb-tomcat50.sar/ROOT.war/
                            18:02:09,453 WARN [DeploymentInfo] Only the root deployment can set the loader repository, ingoring config=null
                            18:02:09,485 INFO [TomcatDeployer] deploy, ctxPath=/jbossmq-httpil, warUrl=file:/C:/jboss-3.2.5/server/myserver/deploy/jms/jbossmq-httpil.sar/jbossmq-httpil.war/
                            18:02:10,016 INFO [DefaultDS] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:service=LocalTxCM,name=DefaultDS to JNDI name 'java:/DefaultDS'
                            18:02:10,641 INFO [IQueue] Bound to JNDI name: queue/IQueue
                            18:02:10,641 INFO [CQueue] Bound to JNDI name: queue/CQueue
                            18:02:10,813 INFO [UILServerILService] JBossMQ UIL service available at : /0.0.0.0:8093
                            18:02:10,953 INFO [DLQ] Bound to JNDI name: queue/DLQ
                            18:02:10,953 INFO [OracleDS] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:service=LocalTxCM,name=OracleDS to JNDI name 'java:/OracleDS'
                            18:02:11,657 INFO [EjbModule] Deploying IConsumerMDB
                            18:02:11,860 INFO [EjbModule] Deploying CConsumerMDB
                            18:02:13,141 INFO [EJBDeployer] Deployed: file:/C:/jboss-3.2.5/server/myserver/deploy/MDB.jar/
                            18:02:13,422 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=file:/C:/jboss-3.2.5/server/myserver/deploy/jmx-console.war/
                            18:02:14,938 INFO [TomcatDeployer] deploy, ctxPath=/web-console, warUrl=file:/C:/jboss-3.2.5/server/myserver/tmp/deploy/tmp4528web-console.war/
                            18:02:18,391 INFO [Server] JBoss (MX MicroKernel) [3.2.5 (build: CVSTag=JBoss_3_2_5 date=200406251954)] Started in 41s:219ms
                            18:02:18,391 INFO [Tomcat5] Saw org.jboss.system.server.started notification, starting connectors
                            18:02:18,547 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-0.0.0.0-8080
                            18:02:19,203 INFO [ChannelSocket] JK2: ajp13 listening on /0.0.0.0:8009
                            18:02:19,266 INFO [JkMain] Jk running ID=0 time=0/266 config=null

                            --- Mukund

                            • 11. Re: javax.naming.NameNotFoundException: OracleDS not bound
                              mukundjaiswal

                              hi darranal,

                              if i use jboss 4.0 will i be able to connect ?

                              • 12. Re: javax.naming.NameNotFoundException: OracleDS not bound
                                darranl

                                Items bound to the 'java:' namespace can only be accessed by clients in the same JVM, to access the datasource remotely you will need to have the datasource bound to the global namespace instead.

                                Have a look at this page: -

                                http://wiki.jboss.org/wiki/Wiki.jsp?page=WhyDoIGetNameNotFoundException

                                The <use-java-context> element can be used to stop the datasource from being bound to the java: namespace.

                                Your lookup will just be for the name OracleDS without the 'java:' prefix.

                                • 13. Re: javax.naming.NameNotFoundException: OracleDS not bound
                                  zhjjava

                                  Configuring a DataSource for remote usage
                                  As of jboss-4.0.0 there is support for accessing a DataSource from a remote client. The one change that is neccessary for the client to be able to lookup the DataSource from jndi is to specify use-java-context=false as shown here:



                                  <local-tx-datasource>
                                  <jndi-name>GenericDS</jndi-name>
                                  <use-java-context>false</use-java-context>
                                  <connection-url>...</connection-url>
                                  ...

                                  This results in the DataSource being bound under the jndi name "GenericDS?" instead of the default of "java:/GenericDS" which restricts the lookup to the same vm as the jboss server.

                                  http://wiki.jboss.org/wiki/Wiki.jsp?page=ConfigDataSources

                                  Your lookup will just be for the name "OracleDS" or "java:/OracleDS" ,

                                  like "UserTransaction"/"java:/UserTransaction"

                                  (????"OracleDS" ? "java:/OracleDS" )

                                  My test is meeting with success!