views:

567

answers:

1

I'm trying to figure out how to use datasources for my web service. I have the oracle-ds.xml deployed on my jboss 4.2.3 server, and the datasources are showing as bounded to JNDI names java:TestDS, java:WeatherDS, etc.

I try doing an initialcontext.lookup but I can't find it. I tried referencing the resource in the web.xml but I get "java:WeatherDS has no valid JNDI binding"... I've tried referencing "java:/WeatherDS", "WeatherDS", "java:WeatherDS", "jdbc/WeatherDS" and some others, but I think I need to somehow map the reference name to the jndi name.

I found a snippet of code that says:

...
<resource-ref>
    <res-ref-name>jdbc/DefaultDS</res-ref-name>
    <jndi-name>java:/DefaultDS</jndi-name>
</resource-ref>
...

But, it doesn't say where this file is and what else is needed. I don't know if I need a resource reference for sure or not. Can anyone point me in the direction of some more complete information of how to access the datasource from the code once it has been deployed? I am trying to make it so the connections are pooled for my web service.

A: 

In JBoss-4.2.3 you define a datasource in an XML-File in folder [JBOSS_HOME]/server/[MYSERVER]/deploy/

Create a file in this folder with name: mydatasource-ds.xml.

XML-File content:

<datasources>
  <local-tx-datasource>
    <jndi-name>mydatasource</jndi-name>
    <!-- Properties for SQLServer -->
    <connection-url>jdbc:jtds:sqlserver://hostname:1433/db-name;TDS=8.0;lastUpdateCount=true;sendStringParametersAsUnicode=false</connection-url>
    <driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
    <!-- Properties for SQLServer end -->
    <user-name>name</user-name>
    <password>pwd</password>
    <min-pool-size>5</min-pool-size>
    <max-pool-size>50</max-pool-size>
    <idle-timeout-minutes>15</idle-timeout-minutes>
    <blocking-timeout-millis>15000</blocking-timeout-millis>
  </local-tx-datasource>
</datasources>

To can access these datasource from every application deployed in the same JBoss by normal JNDI lookup.

IMPORTANT: Use prefix java:/ in the jndi name in your code. Full JNDI-Name in your application for the datasource above is java:/mydatasource

Daniel Murygin