Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems using Tomcat JDBC Connection Pool in Tomcat 7
    primarykey
    data
    text
    <p>In server.xml:</p> <pre><code>&lt;GlobalNamingResources&gt; &lt;Resource name="jdbc/ArchiveDB" auth="Container" type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" ...etc </code></pre> <p>In web.xml:</p> <pre><code>&lt;resource-ref&gt; &lt;description&gt;Archive Database&lt;/description&gt; &lt;res-ref-name&gt;jdbc/ArchiveDB&lt;/res-ref-name&gt; &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt; &lt;res-auth&gt;Container&lt;/res-auth&gt; &lt;/resource-ref&gt; </code></pre> <p>My Code:</p> <pre><code>Context ic = new InitialContext(); DataSource ds = (DataSource) ic.lookup( "java:/comp/env/jdbc/ArchiveDB" ); </code></pre> <p>I am getting the following exception:</p> <pre><code>java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.BasicDataSource cannot be cast to org.apache.tomcat.jdbc.pool.DataSource </code></pre> <p>Any idea what I have got wrong? It seems that the factory field in the resource is not being used, but I have no idea how to find out why. Any ideas how I can progress?</p> <p>Update 1. Delving into source code, found the following in ResourceFactory.java</p> <pre><code>if (ref.getClassName().equals("javax.sql.DataSource")) { String javaxSqlDataSourceFactoryClassName = System.getProperty("javax.sql.DataSource.Factory", Constants.DBCP_DATASOURCE_FACTORY); </code></pre> <p>I guess I have to set that system property so it doesn't revert to default.</p> <p>Update 2. Have now set the following for startup:</p> <pre><code>-Djavax.sql.DataSource.Factory=org.apache.tomcat.jdbc.pool.DataSourceFactory </code></pre> <p>And getting different error:</p> <pre><code>09-Jun-2011 14:48:20 org.apache.naming.NamingContext lookup WARNING: Unexpected exception resolving reference java.sql.SQLException at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:243) Caused by: java.lang.NullPointerException at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:236) ... 57 more javax.naming.NamingException at org.apache.naming.NamingContext.lookup(NamingContext.java:843) </code></pre> <p>I guess it is not able to pick up the driver info I specified.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload