4 Replies Latest reply on Jun 22, 2010 10:29 AM by Jithu mada

    Looking up datasource defined in Jboss

    Jithu mada Newbie

      Hi,

       

      I need to lookup a datasource defined in Jboss from a standalone Java program. Both are running on the same machine. This is the code I am using to lookup,but I a getting NameNotFoundException. Can anyone please tell if there is anything incorrect in the code. The Jboss version is 5.1.0 GA and Java version is 1.6.0 and the OS is AIX 6.1.

       

       


      Properties properties = new Properties();
      properties.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY ,"org.jnp.interfaces.NamingContextFactory");
      properties.setProperty(InitialContext.PROVIDER_URL,"jnp://localhost:1099");
      InitialContext ic = new InitialContext(properties);
      if(ic!=null)
      {
      DataSource ds = (DataSource)ic.lookup("DB2DS");
      con = ds.getConnection();
      }

       

       

      db2-ds.xml file in Jboss

       

       

       

      <datasources>

      <local-tx-datasource>

      <jndi-name>DB2DS</jndi-name>

      <use-java-context>true</use-java-context>

      <connection-url>jdbc:db2://localhost:30000/sds</connection-url>

      <driver-class>com.ibm.db2.jcc.DB2Driver</driver-class>

      <user-name></user-name>

      <password></password>

      <min-pool-size>10</min-pool-size>

      <max-pool-size>10</max-pool-size>

      <!--

      sql to call when connection is created <new-connection-sql>some

      arbitrary sql</new-connection-sql>

      -->

       

      <!--

      sql to call on an existing pooled connection when it is obtained from

      pool <check-valid-connection-sql>some arbitrary

      sql</check-valid-connection-sql>

      -->

       

      <set-tx-query-timeout />

      <query-timeout>300</query-timeout>

       

      <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml -->

      <metadata>

      <type-mapping>DB2</type-mapping>

      </metadata>

      </local-tx-datasource>

      </datasources>

       

       

       

      Any replies greatly appreciated.