JBoss Database Connection Pool

JBoss Database Connection Pool

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.

JDO not saving object


Filter a date property between a begin and end Dates with JDOQL
The pool in JBoss is all handled in the DataSource configuration.

Jeditable: how to set parameters based on dom element attributes
Here is the HowTo.

jeditable not working [closed]
The web app would have to do a JNDI lookup for the datasource to get the database connection rather than doing a direct JDBC URL, and then you will have pooling..
Experience with Hudson - Building matrix project
Transactions are another story, though..
ant - not recognized as an internal
EDIT: In response to your comment about how this affects the code, this is what it looks like:.
Hudson Build-Time Trend Plugin?
String jndiPath = "java:DataSourceJNDIName"; //The exact prefix here has a lot to do with clustering, etc., but if you are using one JBoss instance standalone, this works. 

Hudson gitorious plugin?
Context ctx = new InitialContext(); DataSource ds = (DataSource) PortableRemoteObject.narrow(ctx.lookup(jndiPath), DataSource.class); Connection c = ds.getConnection();
Technically speaking the PortableRemoteObject.narrow isn't necessary in a JBoss (4.2.2 anyway) single server configuration for sure, but it is more proper J2EE standard code, as general application servers don't have to return an object of the right type just for doing a Context.lookup.. The above doesn't cover the resource utilization and error handling issues.

You are supposed to close that Context object when you are done with it, and of course the database connection, although JBoss will yell at you if you forget to close the database connection and the transaction ends, and close it for you.. Anyway, that Connection object is usable just as much as DriverManager.getConnection(url);.


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> <!--  <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> 
<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.


You don't have to change anything.

When you select the right kind of data source (local-tx-datasource / xa-datasource), connection handling and TX is done for you.

In $JBoss/docs/examples/jca you will find templates for virtually every database, that you can just reuse.. If you are using XA, you need to configure Tx-recovery.

See this posting on a how-to: http://management-platform.blogspot.com/2008/11/transaction-recovery-in-jbossas.html (well, perhaps not a how-to in the standalone mode, but in conjunction with the Jopr source code)..

62 out of 100 based on 27 user ratings 652 reviews