Discussions

General J2EE: Configuring JNDI Datasource (MySQL) in JBOSS 4.0.2

  1. Im running a webapplication that connects a MySQL Datasource via Hibernate and JNDI.

    In the hibernate.cfg.xml i have:

    #################################################
    <property name="connection.datasource">java:comp/env/jdbc/jndi-name</property>
    #################################################

    Additionaly i create a corresponding in my AppServer. This works in Tomcat and Resin without Problem.

    Now i am trying to run the same Webapplication in JBOSS-4.0.2.
    I want to configure my MySQL Database as JNDI-bound Datasource in JBOSS.

    My Steps:


    1. Copy JDBC Driver to $JBOSS_HOME$/server/default/lib/
    2. i copied the sample from $JBOSS_HOME$/docs/examples/jca/mysql-ds.xml
    to $JBOSS_HOME$/server/default/deploy

    my mysql-ds.xml looks like this:

    ################################################
    <?xml version="1.0" encoding="UTF-8"?>

    <datasources>
      <local-tx-datasource>
        <jndi-name>comp/env/jdbc/jndi-name</jndi-name>
        <connection-url>jdbc:mysql://localhost:3306/dbname</connection-url>
        <driver-class>org.gjt.mm.mysql.Driver</driver-class>
        <user-name>user</user-name>
        <password>password</password>
        <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
        <!-- 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>
          -->

        <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
        <metadata>
           <type-mapping>mySQL</type-mapping>
        </metadata>
      </local-tx-datasource>
    </datasources>
    #######################################################

    When i start JBOSS, it says:

    #######################################################
    13:36:04,149 INFO [WrapperDataSourceService] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:name=comp/env/jdbc/jndi-name,service=DataSourceBinding to JNDI name 'java:comp/env/jdbc/jndi-name'
    #######################################################


    When i open my WebApp in Browser it says:


    #######################################################
    13:47:29,918 FATAL [DatasourceConnectionProvider] Could not find datasource: java:comp/env/jdbc/jndi-name
    javax.naming.NameNotFoundException: jdbc not bound
    #######################################################

    I must be missing something. Any Help is appreciated.
    Thx!

    Threaded Messages (3)

  2. This all works perfect if i bind my jndi-datasource directly under "java:jndi-name". For reasons of compatibility i want to move my jndi-binding to "java:comp/env/jdbc/jndi-name"

    Then jboss says:

    Could not find datasource: java:comp/env/jdbc/jndi-name
    javax.naming.NameNotFoundException: jdbc not bound
  3. could u have a try[ Go to top ]

    1.config datasource:
    <!--test_oracle_ds.xml-->
    <datasources>
      <local-tx-datasource>
        <jndi-name>jdbc/test</jndi-name>
    ....

      config in web.xml and jboss-web.xml

      Maybe needn't config in web.xml,could u have a try?
      <!--web.xml-->
      <resource-ref>
       <description>DB Connection</description>
         <res-ref-name>jdbc/test</res-ref-name>
         <res-type>javax.sql.DataSource</res-type>
         <res-auth>Container</res-auth>
      </resource-ref>
    ==============================
      <!--jboss-web.xml-->
    <jboss-web>
     <resource-ref>
            <res-ref-name>jdbc/test</res-ref-name>
            <jndi-name>java:/jdbc/test</jndi-name>
        </resource-ref>
    </jboss-web>

    3.java code

    Context ctx = new javax.naming.InitialContext();
              DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/test");
  4. Thanks very Much[ Go to top ]

    Thank you very much..., with your help i may able to solve my problem ....connection of jboss with oracle using JNDI..........