You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by mi...@barclayscapital.com on 2005/01/19 10:00:13 UTC

Getting DBCP working through Tomcat 4.1

Hello all, and apologies if I am asking a question which has been asked
before (I presume it has but I can't find anything after comprehensive
searching).

I am trying to get a simple Tomcat application up using DBCP, and got
BasicDataSource working fine. However, our applications all run under
their own identities, and therefore need to be able to get connections
based on username. I have tried using PerUserPoolDataSource and
SharedPoolDataSource with no luck. The exception I am currently getting
is as follows:
"Must set the ConnectionPoolDataSource through setDataSourceName or
setConnectionPoolDataSource before calling getConnection"

My configuration is as follows:
Tomcat 4.1.24, DBCP 1.2.1, Sybase jConnect 5.0 build 10229 (Sybase and
DBCP jars in <tomcat_base>/common/lib)

Following is an extract of my configuration files, and application code.
I would greatly appreciate some help - this is beginning to drive me
insane!

Thanks in advance,
Mike

Server.xml extract:
------------------------
<DefaultContext>
	<Resource name="jdbc/TestDB" auth="Container"
type="org.apache.commons.dbcp.datasources.PerUserPoolDataSource"/>
	<ResourceParams name="jdbc/TestDB">
		<parameter>
			<name>factory</name>
	
<value>org.apache.commons.dbcp.datasources.PerUserPoolDataSourceFactory<
/value>
		</parameter>
		<parameter>
			<name>driverClassName</name>
			<value>com.sybase.jdbc2.jdbc.SybDrivers</value>
		</parameter>
		<parameter>
			<name>url</name>
	
<value>jdbc:sybase:Tds:<myServerName>:<myPort>?charset=iso_1</value>
		</parameter>
		<parameter>
			<name>maxActive</name>
			<value>10</value>
		</parameter>
		<parameter>
			<name>maxIdle</name>
			<value>2</value>
		</parameter>
		<parameter>
			<name>maxWait</name>
			<value>-1</value>
		</parameter>
		<parameter>
			<name>defaultReadOnly</name>
			<value>false</value>
		</parameter>
		<parameter>
			<name>defaultAutoCommit</name>
			<value>false</value>
		</parameter>
	</ResourceParams>
</DefaultContext>

Web.xml
------------------------
<resource-ref>
	<res-ref-name>jdbc/TestDB</res-ref-name>
	
<res-type>org.apache.commons.dbcp.datasources.PerUserPoolDataSource</res
-type>
	<res-auth>Container</res-auth>
</resource-ref>
=================
Application code extract

ctx = new InitialContext();

DataSource ds = null;
if (ctx != null) {
	ds = (DataSource) ctx.lookup("java:comp/env/jdbc/TestDB");
	Connection conn = ds.getConnection(userName, passWord);  //
<---- exception on this line

	Statement stm = conn.createStatement();
	ResultSet results = stm.executeQuery("select db_name()");

	if (results.next())
		out.write("Successfully connected to database " +
results.getString(1));
}
------------------------



------------------------------------------------------------------------
For more information about Barclays Capital, please
visit our web site at http://www.barcap.com.


Internet communications are not secure and therefore the Barclays 
Group does not accept legal responsibility for the contents of this 
message.  Although the Barclays Group operates anti-virus programmes, 
it does not accept responsibility for any damage whatsoever that is 
caused by viruses being passed.  Any views or opinions presented are 
solely those of the author and do not necessarily represent those of the 
Barclays Group.  Replies to this email may be monitored by the Barclays 
Group for operational or business reasons.

------------------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Getting DBCP working through Tomcat 4.1

Posted by Dirk Verbeeck <di...@pandora.be>.
Hi Mike

You need a DriverAdapterCPDS and a PerUserPoolDataSource.
Try the following configuration:

<Resource name="jdbc/TestDBCPDS" auth="Container" 
type="org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS"/>
<ResourceParams name="jdbc/TestDBCPDS">
<parameter><name>factory</name><value>org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS</value></parameter>
<parameter><name>user</name><value>sa</value></parameter>
<parameter><name>password</name><value></value></parameter>
<parameter><name>driver</name><value>com.sybase.jdbc2.jdbc.SybDrivers</value></parameter>
<parameter><name>url</name><value>jdbc:sybase:Tds:<myServerName>:<myPort>?charset=iso_1</value></parameter>
</ResourceParams>

<Resource auth="Container" name="jdbc/TestDB" 
type="org.apache.commons.dbcp.datasources.PerUserPoolDataSource"/>
<ResourceParams name="jdbc/TestDB">
<parameter><name>factory</name><value>org.apache.commons.dbcp.datasources.PerUserPoolDataSourceFactory</value></parameter>
<parameter><name>defaultMaxActive</name><value>10</value></parameter>
<parameter><name>defaultMaxIdle</name><value>2</value></parameter>
<parameter><name>defaultMaxWait</name><value>-1</value></parameter>
<parameter><name>dataSourceName</name><value>java:comp/env/jdbc/TestDBCPDS</value></parameter>
</ResourceParams>

-- Dirk

mike.raath@barclayscapital.com wrote:
> Hello all, and apologies if I am asking a question which has been asked
> before (I presume it has but I can't find anything after comprehensive
> searching).
> 
> I am trying to get a simple Tomcat application up using DBCP, and got
> BasicDataSource working fine. However, our applications all run under
> their own identities, and therefore need to be able to get connections
> based on username. I have tried using PerUserPoolDataSource and
> SharedPoolDataSource with no luck. The exception I am currently getting
> is as follows:
> "Must set the ConnectionPoolDataSource through setDataSourceName or
> setConnectionPoolDataSource before calling getConnection"
> 
> My configuration is as follows:
> Tomcat 4.1.24, DBCP 1.2.1, Sybase jConnect 5.0 build 10229 (Sybase and
> DBCP jars in <tomcat_base>/common/lib)
> 
> Following is an extract of my configuration files, and application code.
> I would greatly appreciate some help - this is beginning to drive me
> insane!
> 
> Thanks in advance,
> Mike


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org