[JBoss-user] Re: Oracle Connection Pool Setup

2001-07-12 Thread tim . haley



Vinay,
If I understand correctly; you are successfully using DB connections directly
from your beans to access the Oracle database, and you want to change that to
use a connection Pool set up by JBoss.  If that is the case, then you already
have your Oracle thin/OCI driver set up and working correctly.  All you need to
do is set up and use the connection pool.



I put my JDBC driver in the %JBOSS%/lib/ext directory; however, you could use
the class path extension mechanism in jboss.conf to point to wherever your
driver already exists.



Here is the section of my jboss.jcml file regarding the connection pool:

-
 !-- JDBC --
 mbean code=org.jboss.jdbc.JdbcProvider
name=DefaultDomain:service=JdbcProvider
  attribute name=Driversoracle.jdbc.driver.OracleDriver/attribute
 /mbean
 mbean code=org.jboss.jdbc.XADataSourceLoader
name=DefaultDomain:service=XADataSource,name=jdbc/DBName
  attribute name=PoolNamejdbc/DBName/attribute
  attribute
name=DataSourceClassorg.opentools.minerva.jdbc.xa.wrapper.XADataSourceImpl/attribute

  attribute name=Properties/attribute
  attribute name=URLjdbc:oracle:thin:@localhost:1521:DBName
/attribute
  attribute name=GCMinIdleTime120/attribute
  attribute name=JDBCUserusername/attribute
  attribute name=MaxSize10/attribute
  attribute name=Passwordpassword/attribute
 attribute name=GCEnabledfalse/attribute
 attribute name=InvalidateOnErrorfalse/attribute
 attribute name=TimestampUsedfalse/attribute
 attribute name=Blockingtrue/attribute
 attribute name=GCInterval12/attribute
 attribute name=IdleTimeout180/attribute
 attribute name=IdleTimeoutEnabledfalse/attribute
 attribute name=LoggingEnabledfalse/attribute
 attribute name=MaxIdleTimeoutPercent1.0/attribute
 attribute name=MinSize0/attribute
 /mbean
-

Here is my utility class used to get the database connections:

-
package com.acme.Utilities;

import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class DBConnectionFactory
{
 public DBConnectionFactory() { }

 public static final Connection getConnection()
throws SQLException, NamingException
 {
  //***
  // Use DataSource with the deployment descriptor
  // to get a Database Connection from
  // the Pool maintained by theserver.
  InitialContext ic = new InitialContext();
  DataSource ds = (DataSource)ic.lookup(java:jdbc/DBName);
  Connection con= ds.getConnection();
  if (con.getAutoCommit())
  {
   con.setAutoCommit(false);
  }

  return con;

 }
}
-

Every bean method that needs access to the database has a call similar to:
 con = DBConnectionFactory.getConnection();
where con is defined as:

 protected Connection con   = null;
when the method is finished with the connection:

-
 finally
 {
  try {
   if (result != null)
   {
result.close();
result = null;
   }
  } catch (SQLException se){se.printStackTrace();}
  try {
   if (pStatement != null)
   {
pStatement.close();
pStatement = null;
   }
  } catch (SQLException se){se.printStackTrace();}
  try {
   if (con != null)
   {
con.close();
con = null;
   }
  } catch (SQLException se){se.printStackTrace();}
 }
-
Good luck,

- Tim




To:   Tim Haley/SAR/Global@Global
cc:

Subject:  Hi Tim



Hi Tim,
  I got ur mail-id Jboss mailing list.
  If you can help me I would be greatful to you.
  I'm developing EJB's and using JBoss. I want to do connection pooling.
  What properties have to set and where for enabling connection pooling in
JBoss?
  And also code for using instances of DB connection?
  My software configuration is as follows:
  JBoss-2.2.2_Tomcat-3.2.2  with Oracle(8.1.7)
  Everything is setup and running successfully. Now my aim is to enable
connection
  pooling using Oracle thin/OCI drivers. I think I 've to set properties in
jboss.jcml
  but how the properties should look like I don't know. I'm confused.
  Pl help me.

Thanks very much
Vinay Ram




___
JBoss-user mailing list
[EMAIL PROTECTED]

Re: [JBoss-user] Re: Oracle Connection Pool Setup

2001-07-12 Thread danch (Dan Christopherson)

[EMAIL PROTECTED] wrote:

 
   // the Pool maintained by theserver.
   InitialContext ic = new InitialContext();
   DataSource ds = (DataSource)ic.lookup(java:jdbc/DBName);


For portability, you should use an ENC name here 
(java:comp/env/jdbc/DBName), but that does require a resource-ref 
stanza in ejb-jar.xml for each bean (or in web.xml for servlet/JSP use) 
that uses this code, and will require a resource-ref (and maybe a 
resource-manager, depending on what version of jboss you're using) in 
jboss.xml (jboss-web.xml for servlet/JSP) to map that to any pool other 
than DefaultDS.

WHat you have works fine in JBoss, but you'll need to change code and 
recompile for other app servers.


   Connection con= ds.getConnection();
   if (con.getAutoCommit())
   {
con.setAutoCommit(false);


You don't really need that (the pools do it for you).

-danch



___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user