1 Reply Latest reply on Sep 29, 2004 2:15 PM by timmorrow

    External Hypersonic

    jerryp64

      I have been given a task of showing how to connect to an external database using JBoss. I am using a standalone version of Hypersonic. I have created a new hsqldb-ds.xml file that I think should be connecting to the external db.

      <datasources>
       <local-tx-datasource>
       <jndi-name>HypersonicDS</jndi-name>
       <connection-url>jdbc:hsqldb:hsql://localhost/bookdb</connection-url>
       <driver-class>org.hsqldb.jdbcDriver</driver-class>
       <user-name>sa</user-name>
       <password></password>
       <min-pool-size>5</min-pool-size>
       <max-pool-size>20</max-pool-size>
       <idle-timeout-minutes>0</idle-timeout-minutes>
       <track-statements/>
       <metadata>
       <type-mapping>Hypersonic SQL</type-mapping>
       </metadata>
       <depends>jboss:service=Hypersonic</depends>
       </local-tx-datasource>
       <mbean code="org.jboss.jdbc.HypersonicDatabase"
       name="jboss:service=Hypersonic">
       <attribute name="Port">1701</attribute>
       <attribute name="Silent">true</attribute>
       <attribute name="Database">default</attribute>
       <attribute name="Trace">false</attribute>
       <attribute name="No_system_exit">true</attribute>
       </mbean>
      </datasources>
      

      When I put a new version of this file in the default/deploy directory I get a message that the Datasource has been bound to the name 'java:HypersonicDS'.

      In my Java app I am connecting successfully to the naming service, but I get a NameNotFoundException when I try and access the JNDI name. I have tried several different versions. I am trying to get this to work before I deploy an Entity bean that uses the external Hypersonic database.
      Thanks.

        • 1. Re: External Hypersonic
          timmorrow

          Define a resource reference in web.xml, then map that to the JBoss jndi name in jboss-web.xml and look it up (using the name defined in web.xml) from the container java:comp/env context.

          web.xml:

          <resource-ref>
           <res-ref-name>jdbc/myDS</res-ref-name>
           <res-type>javax.sql.DataSource</res-type>
           <res-auth>Container</res-auth>
          </resource-ref>


          jboss-web.xml:
          <resource-ref>
           <res-ref-name>jdbc/myDS</res-ref-name>
           <jndi-name>java:/HypersonicDS</jndi-name>
          </resource-ref>


          Code:
          InitialContext ic = new InitialContext();
          DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/myDS");


          Tim