4 Replies Latest reply on Aug 12, 2008 10:03 AM by Bir Adam

    Datasource is null

    Bir Adam Newbie

      Hi there, I have the following problem, I am trying to connect to database via Jndi but I get datasource is null, here is my codes:
      try {
      ic = new InitialContext();
      ds = (DataSource)ic.lookup("java:/SybaseDS");
      conn = ds.getConnection();

      }
      catch(NamingException ne)
      {
      logger.debug("Naming Exception thrown: " +ne.getMessage());
      }
      catch(Exception e){
      logger.error("Other connection Exception thrown: " +e.getMessage());
      }
      return conn;
      }

      the jndi name on sybase-ds.xml is (I am using Sybase)

      <local-tx-datasource>
      <jndi-name>SybaseDS</jndi-name>

      the database url:
      <connection-url>jdbc:sybase:Tds:wi3db1.caci.com:5000/SQ3XX</connection-url>
      <driver-class>com.sybase.jdbc2.jdbc.SybDataSource</driver-class>

      and the mapping is:

      <type-mapping>Sybase</type-mapping>



      other config files uses java:/SybaseDS as data-source name
      here jbobssjaws.xml:

      java:/SybaseDS
      <type-mapping>Sybase</type-mapping>
      false

      here is standardjbosscmp-jdbc.xml:

      java:/SybaseDS
      -------------------------------------

      is there anything I making wrong

      Best Regards


        • 1. Re: Datasource is null
          Sandor Fiedler Newbie

          Do you have verified, that the datasource is deployed correct by using the JndiView-Service. Please post the output of that.

          • 2. Re: Datasource is null
            Bir Adam Newbie

            hi itsme

            Here is the jndi view:

            java: Namespace
            +- SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory)
            +- DefaultJMSProvider (class: org.jboss.jms.jndi.JNDIProviderAdapter)
            +- comp (class: javax.naming.Context)


            +- JDBC (class: org.jnp.interfaces.NamingContext)
            | +- SybaseDS (class:
            org.jboss.resource.adapter.jdbc.WrapperDataSource)


            +- JmsXA (class: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl)
            +- jaas (class: javax.naming.Context)
            | +- JmsXARealm (class: org.jboss.security.plugins.SecurityDomainContext)
            +- timedCacheFactory (class: javax.naming.Context)
            Failed to lookup: timedCacheFactory, errmsg=org.jboss.util.TimedCachePolicy
            +- TransactionPropagationContextExporter (class: org.jboss.tm.TransactionPropagationContextFactory)
            +- StdJMSPool (class: org.jboss.jms.asf.StdServerSessionPoolFactory)
            +- Mail (class: javax.mail.Session)
            +- TransactionPropagationContextImporter (class: org.jboss.tm.TransactionPropagationContextImporter)
            +- TransactionManager (class: org.jboss.tm.TxManager)

            Here is the JBOSS.JDBC:
            jboss.jdbc
            datasource=SybaseDS,service=metadata
            service=SQLExceptionProcessor
            service=metadata


            however, one thing to note: my datasource lookup is as follows:
            ds = (DataSource)ic.lookup("java:jdbc/SybaseDS");

            and I have change: jndi name in
            the jndi name on sybase-ds.xml is (I am using Sybase)

            <local-tx-datasource>
            <jndi-name>JDBC/SybaseDS</jndi-name>

            the database url:
            <connection-url>jdbc:sybase:Tds:wi3db1.caci.com:5000/SQ3XX</connection-url>
            <driver-class>com.sybase.jdbc2.jdbc.SybDataSource</driver-class>

            and the mapping is:

            <type-mapping>Sybase</type-mapping>

            key point:
            I can bind the datasource to jndi -- since the catch for catching naming error is passed alright, but I caught the general exception.

            thanks
            badam571

            • 3. Re: Datasource is null
              Sandor Fiedler Newbie

              Try to chnage your lookup code to

              ...
              ds = (DataSource)ic.lookup("java:JDBC/SybaseDS");
              ...
              


              • 4. Re: Datasource is null
                Bir Adam Newbie

                itsme

                what is the difference between the three different jndi context:

                java:, comp, and global jndi? do I need to move my context binding to the global context?

                bada571