JBoss Database Connection Pool

connection-poolingdatasourcejboss

I am new to jboss and i have been asked to incorporate jboss connection pooling mechanism with an existing web application. Considering that a web application database layer is properly written i.e. all resultsets, statements and connections being closed properly when not needed, What all code changes i will have to make in my web app after i have configured the jboss datasource properly.

Can anybody please point me to a tutorial or a code sample which uses jboss datasource in a web app.

Best Answer

first create an xml file by name xxx-ds.xml and place this file in server/default/deploy/xxx-ds.xml

<datasources>
<local-tx-datasource>
<jndi-name>/jdbc/Exp</jndi-name>
<type-mapping>SQL</type-mapping>
<connection-url>jdbc:microsoft:sqlserver://          </connection-url>
<driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
<user-name></user-name>
<password></password>
<min-pool-size>5</min-pool-size>
<max-pool-size>1000</max-pool-size>
</local-tx-datasource>
</datasources>

jboss-web.xml

<jboss-web>
<!--  <security-domain flushOnSessionInvalidation="false"/>-->
<!--  <context-root>/BSI</context-root>-->
  <resource-ref>
        <description>Database connection resource</description>
        <res-ref-name>jdbc/Exp</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <jndi-name>java:/jdbc/Exp</jndi-name>
        <res-auth>Container</res-auth>
    </resource-ref>
</jboss-web>

web.xml

<resource-ref>
    <description>Database connection resource</description>   
    <res-ref-name>jdbc/Exp</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

and now in your .java file

javax.naming.Context ctx1 = new javax.naming.InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource) ctx1.lookup("java:comp/env/jdbc/Exp");
con = ds.getConnection();

***** make sure that resource ref name should be same in all place

Related Topic