Techie:Techie Main/Java/JBoss/Connection Pool

From FFL Wiki
Revision as of 09:55, 27 May 2010 by Phallus (talk | contribs) (Created page with 'Follow all these steps to configure a datasource that is portable across servers == Create datasource == Example MySQL datasource which can be accessed with JNDI at java:Fantac…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Follow all these steps to configure a datasource that is portable across servers

Create datasource

Example MySQL datasource which can be accessed with JNDI at java:FantacyDS . This file should be created in the server's deploy directory and the file name must end '-ds.xml' .

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
    <local-tx-datasource>
        <jndi-name>FantacyDS</jndi-name>
        <connection-url>jdbc:mysql://localhost:3306/fantacy</connection-url>
        <driver-class>com.mysql.jdbc.Driver</driver-class>
        <user-name>xxxx</user-name>
        <password>yyyy</password>
        <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
        <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
        <metadata>
        <type-mapping>mySQL</type-mapping>
        </metadata>
    </local-tx-datasource>
</datasources>


Configure a web resource reference

Create a file called jboss-web.xml in the web apps WEB-INF directory with the following content. This will be ignored by other app servers so we can deploy this elsewhere without problems.

<jboss-web>
    <resource-ref>
        <res-ref-name>jdbc/FantacyDS</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <jndi-name>java:FantacyDS</jndi-name>
    </resource-ref>
</jboss-web>


Use the resource in the web app

Make use of the resource ref in the web apps deployment descriptor, WEB-INF/web.xml . This is standard Java EE config. This datasource will now be available using JNDI at java:comp/env/jdbc/FantacyDS .

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

Note: this is the same web.xml config as we used for tomcat confirming that this is portable across servers