4 Replies Latest reply on Jan 13, 2007 4:59 AM by Stephan Fudeus

    Problem getting Datasource vi JNDI

    Markus Jais Newbie

      hello

      I am trying to get the Quartz scheduler running:

      I have a local jboss (4.0.3) running on my machine and configured the Quartz datasource.

      via the JBoss JMX console I can see that the datasource is bound:


      java: Namespace

      +- jaas (class: javax.naming.Context)
      .............
      +- jdbc (class: org.jnp.interfaces.NamingContext)
      | +- QuartzDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
      | +- QuartzNoTxDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
      ..............


      I wrote the following client programme to access the datasource:

      class ContextTest {

      public static DataSource getDataSource(String dataSourceJndiName) {
      DataSource dataSource = null;

      Properties prop = new Properties();
      prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      prop.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
      prop.put(Context.PROVIDER_URL, "jnp://localhost:1099");

      try {
      Context ctx = new InitialContext(prop);
      dataSource = (DataSource) ctx.lookup(dataSourceJndiName);

      } catch (ClassCastException cce) {
      cce.printStackTrace();
      } catch (NamingException ne) {
      ne.printStackTrace();
      }

      return dataSource;
      }

      public static void main(String[] args) {
      DataSource ds = getDataSource("java:comp/env/jdbc/QuartzDS");
      System.out.println(ds.toString());
      }
      }


      and I get this error:
      javax.naming.NameNotFoundException: comp not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:514)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:522)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:528)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:252)


      I also tried many other combinations for the JNDI Name, but I never managed
      to get the Datasource.
      calling the code from within a JSF application (deployed on the JBoss where the
      Quartz datasource is) doesn't work either.

      any idea what's wrong here ?

      Markus