2 Replies Latest reply on Jan 15, 2007 8:03 PM by omar_azrat

    Can't get JCA datasource using JNDI

    omar_azrat

      Actually I'm deploying a website for JBoss. Mi commitment is make this site to work with this databases:


      ORACLE
      MYSQL
      SQL SERVER


      My fellow and me wrote the access to the database in a simple class (this project has no entity-beans). Servlets and a java application need access to database. Our current database is mysql.

      Finding out a way to configure access to database, I found that using JCA its possible to bind connections to databases using files with the name in the format *ds.xml.
      What I did is to work with a file I called DB-ds.xml (according JCA standard) and wrote an initial mysql configuration. Below is the content of this file:

      <?xml version="1.0" encoding="UTF-8"?>
      <!-- WEBCOMJAFL. Archivo de conexión a la base de datos. -->
      <datasources>
       <!-- Datasource config for MySQL using 3.0.9 available from:
       http://www.mysql.com/downloads/api-jdbc-stable.html-->
       <no-tx-datasource>
       <jndi-name>comp/env/jdbc/WCJFDB</jndi-name>
       <use-java-context>true</use-java-context>
       <connection-url>jdbc:mysql://localhost/webcomjafl</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
       <user-name>webcomjafl</user-name>
       <password></password>
       <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
       </no-tx-datasource>
      </datasources>

      Data in this file is fine (user=webcomjafl, no password)

      After copying this file into server\default\deploy directory of JBoss, I got this message:
      15:59:25,727 INFO [WrapperDataSourceService] Bound ConnectionManager 'jboss.jca
      :service=DataSourceBinding,name=comp/env/jdbc/WCJFDB' to JNDI name 'java:comp/env/jdbc/WCJFDB'

      What means that binding was successful.

      I've tried calling this resource (comp/env/jdbc/WCJFDB) from a java-test application, but I had an error message:

      before
      javax.naming.NameNotFoundException: comp not bound
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
       at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
       at javax.naming.InitialContext.lookup(InitialContext.java:392)
       at devenet.com.workflow.DBConnectionTest.main(DBConnectionTest.java:38)


      This is my source code:
      public static void main(String[] args) {
       try {
      
       InitialContext ctx = new InitialContext();
       System.out.println("before");
       Object connection = ctx.lookup("java:comp/env/jdbc/WCJFDB");
       System.out.println("after");
      
       } catch (Exception e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       }
      
       }


      Notes:

      This is my jndi.properties file:
      ### JBossNS properties
      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.provider.url=jnp://localhost:1099
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces


      I've installed JBoss version 4.0.5, with all components (full), with jmx interfaces no secured (jmx-console.war, web-console.war, jmx-invoker-service, http invoker).

      I'll be thankful for any help.

      Néstor Arias