Connection Pool configuration <Context path="/NASApp" docBase="NASApp" reloadable="true"> <Resource name="jdbc/pool" auth="Container" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/pool"> <parameter> <name>user</name> <value>DES</value> </parameter> <parameter> <name>password</name> <value>DES</value> </parameter> <parameter> <name>driverClassName</name> <value>oracle.jdbc.driver.OracleDriver</value> </parameter> <parameter> <name>driverName</name> <value>jdbc:oracle:oci8:MyUser/MyPass@MyDatabase</value> </parameter> </ResourceParams> </Context> Server.xml
Jar with the driver <TOMCAT>\common\lib\classes12.jar Get a connection from the Connection Pool // Obtain our environment naming context javax.naming.Context initCtx = new InitialContext(); javax.naming.Context context = (Context) initCtx.lookup("java:comp/env"); System.out.println("TRY CONNECT"); javax.sql.DataSource ds = (javax.sql.DataSource)context.lookup("jdbc/pool"); connection = ds.getConnection(); System.out.println("CONNECTED"); Cast the PreparedStatement to OraclePreparedStatement import oracle.jdbc.driver.OraclePreparedStatement; (...) pstat = connection.getJDBCPreparedStatement(query); pstat.setFetchSize(fetchSize); System.out.println( "pstat.getClass()" + pstat.getClass() ); if(pstat instanceof oracle.jdbc.driver.OraclePreparedStatement) { System.out.println("Yes - STATprepOracle"); } else { System.out.println("No - STATprepOracle"); if(pstat instanceof oracle.jdbc.driver.OracleStatement) { System.out.println("Yes - STAToracle"); } if(pstat instanceof java.sql.Statement) { System.out.println("Yes - STATsql"); } if(pstat instanceof java.sql.PreparedStatement) { System.out.println("Yes - STATprepSql"); } Class c = pstat.getClass(); System.out.println( "c.getName(): " + c.getName() ); System.out.println( "c.getPackage(): " + c.getPackage() ); System.out.println( "c.getClassLoader(): " + c.getClassLoader() ); } oracle.jdbc.driver.OraclePreparedStatement ostat = null; try { ostat = (oracle.jdbc.driver.OraclePreparedStatement) pstat; } catch (Throwable e) { e.printStackTrace(); } ostat.defineColumnType(CODIGOPERFIL_ROW, Types.VARCHAR); ostat.defineColumnType(TIPOERROCLO_ROW, Types.VARCHAR); Console output TRY CONNECT CONNECTED pstat.getClass()class oracle.jdbc.driver.OraclePreparedStatement No - STATprepOracle Yes - STATsql Yes - STATprepSql c.getName(): oracle.jdbc.driver.OraclePreparedStatement c.getPackage(): package oracle.jdbc.driver c.getClassLoader(): StandardClassLoader available: Extension[javax.mail, implementationVendor=Sun Microsystems, Inc., implementationVendorId=com.sun, implementationVersion=1.2, specificationVendor=Sun Microsystems, Inc., specificationVersion=1.2] delegate: false repositories: file:D:\java\tomcat40\common\classes\ file:D:\java\tomcat40\common\lib\activation.jar file:D:\java\tomcat40\common\lib\classes12.jar file:D:\java\tomcat40\common\lib\crimson.jar file:D:\java\tomcat40\common\lib\jaxp.jar file:D:\java\tomcat40\common\lib\jdbc2_0-stdext.jar file:D:\java\tomcat40\common\lib\jta-spec1_0_1.jar file:D:\java\tomcat40\common\lib\ldap.jar file:D:\java\tomcat40\common\lib\mail.jar file:D:\java\tomcat40\common\lib\naming-common.jar file:D:\java\tomcat40\common\lib\naming-resources.jar file:D:\java\tomcat40\common\lib\servlet.jar file:D:\java\tomcat40\common\lib\tyrex-0.9.7.0.jar required: ----------> Parent Classloader: sun.misc.Launcher$AppClassLoader@71732b java.lang.ClassCastException: oracle.jdbc.driver.OraclePreparedStatement (...) at org.apache.jasper.runtime.HttpJspBase.service(Unknown Source) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(Unknown Source) at org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source) at org.apache.jasper.servlet.JspServlet.service(Unknown Source) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source) at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source) at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardContext.invoke(Unknown Source) at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.valves.AccessLogValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.connector.http.HttpProcessor.process(Unknown Source) at org.apache.catalina.connector.http.HttpProcessor.run(Unknown Source) at java.lang.Thread.run(Thread.java:484) java.lang.NullPointerException - - - - - - - - - - QUESTION - - - - - - - - - - I'm trying to configure a Connection Pool in Tomcat 4 to Oracle 8.1.7 database. Everything works fine if I don't cast my PreparedStatement to OraclePreparedStatement, to take advantage of the "defineColumnType" method (this will save 2 roundtrips to the RDBMS when executing the query [that's what the documentation says]). To figure out what class do I have, do the folowing: > => System.out.println( "pstat.getClass()" + pstat.getClass() ); and I get the output => pstat.getClass()class oracle.jdbc.driver.OraclePreparedStatement If I use JBuilder in debug and "Evaluate" the "pstat" object I also see a "oracle.jdbc.driver.OraclePreparedStatement", so probably the "oracle.jdbc.driver.OraclePreparedStatement" was casted to "java.sql.PreparedStatement" right? How can I fix it? Maybe it has something to do with the "tyrex" connection pool. Is there another way to create a connection pool to Oracle 8.1.7 in Tomcat? How? Thanks __________________________________________________ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>