4 Replies Latest reply on Jul 11, 2003 11:18 AM by juhalindfors

    DefaultDS Not Found

    qinding

      After installation of JBoss, I made no change. Start JBoss. Go to jmx-console, Click Service=JNDIView. Click Invoke button under java.lang.Strng list(). I see Java:Namespace. Under it, I see +-DefaultDS. So, DefaultDS is bound to the jndi tree.

      Now, I write a small java program to access to the database using DefaultDS.

      public static void main(String[] args) {

      DataSource ds = null;
      try{
      Properties prop = new Properties();
      prop.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
      prop.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
      prop.setProperty("java.naming.provider.url", "localhost");

      Context jndiCntx = new InitialContext(prop);
      //ds = (DataSource)jndiCntx.lookup("DefaultDS");
      ds = (DataSource)jndiCntx.lookup("java:/DefaultDS");

      }catch(javax.naming.NamingException ne){
      ne.printStackTrace();
      }

      Connection conn = null;
      Statement stmt = null;
      ResultSet rset = null;

      try{

      conn = ds.getConnection();
      System.out.println("Creating statement.");
      stmt = conn.createStatement();
      System.out.println("Executing statement.");
      rset = stmt.executeQuery("Select * from Department");
      System.out.println("Results:");
      int numcols = rset.getMetaData().getColumnCount();
      while(rset.next()) {
      for(int i=1;i<=numcols;i++) {
      System.out.print("\t" + rset.getString(i));
      }
      System.out.println("");
      }
      //}
      } catch(Exception e) {
      e.printStackTrace();
      } finally {
      try { rset.close(); } catch(Exception e) { }
      try { stmt.close(); } catch(Exception e) { }
      try { conn.close(); } catch(Exception e) { }
      ds = null;
      }
      }

      }

      Execute this program: I got this error:
      javax.naming.NameNotFoundException: DefaultDS 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.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
      at sun.rmi.transport.Transport$1.run(Transport.java:148)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
      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:536)
      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:133)
      at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:492)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:471)
      at javax.naming.InitialContext.lookup(InitialContext.java:347)
      at com.qd.dbConnectionConfig.Qding.main(Qding.java:34)
      java.lang.NullPointerException
      at com.qd.dbConnectionConfig.Qding.main(Qding.java:45)


      Did I do something wrong? Is this the correct way to use jndi datasource? Please advise. Thank you very much.

      Qin

        • 1. Re: DefaultDS Not Found
          qinding

          I wanted to add one thing: I copied jboss-client.jar, jboss-common-client.jar, and jnp-client.jar to my program's classpath before I ran my small test program.

          I tried both java:/DefaultDS and DefaultDS but there is no difference. Please help.

          Qin

          • 2. Re: DefaultDS Not Found

            Datasources are not bound to global JNDI namespace. The java: namespace is only available to instances running within the same process (in the same JVM). You cannot lookup a datasource directly from an external process.

            • 3. Re: DefaultDS Not Found
              qinding

              So, Is there a indirect way to bound datasource to the globe jndi namespace?

              I guess I need to create ejbs to get access to the database via DefaultDS. Is it true that EJB homes are bound to the globe jndi namespace, so remote client can call from another vm process?

              Thank you for the advice.

              Qin

              • 4. Re: DefaultDS Not Found

                Yes, create a stateless session bean that interacts with your datasource. This is more scalable and secure approach.