PDA

View Full Version : Chi mi aiuta a configurare una Connection Pool in TomCat


elgordoo
16-08-2007, 23:22
Vorrei configurare TomCat 5.5.15 per una Connection Pool ma ho sempre la stessa eccezione

org.apache.tomcat.dbcp.dbcp.SQLNestedException:
Cannot create JDBC driver

Questi sono i file che ho configurato


Server.xml

<!-- Global JNDI resources -->

<GlobalNamingResources>

<Resource name="jdbc/postgres" auth="Container" type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/postgres">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>org.postgresql.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:postgresql://localhost:5432/MyDB</value>
</parameter>
<parameter>
<name>username</name>
<value>username</value>
</parameter>
<parameter>
<name>password</name>
<value>password</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
</ResourceParams>

</GlobalNamingResources>


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

In Web.xml

<resource-ref>
<description>postgreSQL Datasource example</description>
<res-ref-name>jdbc/postgres</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

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

La classe Java

InitialContext jndiCntx=null;
Connection conn;
Context ctx=null;

try
{
if (dataSource == null)
{
jndiCntx = new InitialContext();

ctx = (Context) jndiCntx.lookup("java:comp/env");

dataSource = (javax.sql.DataSource) ctx.lookup("jdbc/postgres");
}

conn = dataSource.getConnection(); //ECCEZIONE
}