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]