<<I need to use connection pooling in one of my EJB objects and I don't want
to use any Orion specific code>>
Orion totally supports this. Here's what you need to do:

Step 1:
Setup a datasource in orion/config/data-sources.xml.
This is roughly analogous to setting up an ODBC DataSourceName. This
documented on Orion's site.

Step 2:
Add an entry to the deployment descriptor for datasource resource-ref. For
example:

 <resource-ref>
  <res-ref-name>jdbc/mysql_ss1</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Application</res-auth>
 </resource-ref>

This is documented in ejb spec, checkout section 14.4.1.2 of the ejb 1.1
spec.

Step 3:
Add the following code anywhere with in a servlet/jsp or ejb:

Connection conn = null;
try{
    javax.naming.Context ctx = new javax.naming,InitialContext();
    javax.sql.DataSource ds =
(javax.sql.DataSource)ctx.lookup("jdbc/mysql_ss1");
    conn = ds.getConnection();
    .....
}
catch(...){ }
finally{
    if(conn!=null) conn.close();
}

This will automatically use connection pooling.

In my opinion, I think this is one of the nicest features of J2EE,
standardizing (almost hiding) the way connection pooling is handled across
web/ejb servers. I believe MS ASP/ADO has had this feature for some years
now.

Hope this helps.


Dave Ford
Smart Soft - The Java Training Company
http://www.SmartSoftTraining.com


Reply via email to