commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <james_strac...@yahoo.co.uk>
Subject Re: dataSource.getConnection fails from within tomcat
Date Fri, 13 Dec 2002 18:00:43 GMT
Can anyone spot Pauls problem for him? Could it be a class loading issue?

----- Original Message -----
From: "Paul Tomsic" <ptomsic@yahoo.com>
To: <james_strachan@yahoo.co.uk>
Sent: Friday, December 13, 2002 5:55 PM
Subject: dataSource.getConnection fails from within tomcat

> James,
>
> we exchanged a few emails a while ago about a
> persistence problem that I was having from within
> tomcat.
> Sorry to email you directly, but I'm not having any
> success getting answers from the mailing list, so I
> thought I'd take a chance and ask you directly.
> Again, my apologies, but I can't seem to correct this
> problem.
>
> I'm able to connect to a MySQL dB using a stand alone
> file (see below), but when I put the exact same code
> into our application from within Tomcat, I get a
> nullPointer on the
> conn = dataSource.getConnection()
> line.
>
> you wouldn't have any thoughts as to why this is
> happening, or even a suggestion as to where I could
> start troubleshooting, would you?
> It's just odd that I can do it stand-alone, but when
> mixed w/ Tomcat, I get that nullpointer, but no real
> explaination.
>
>
> thanks again, and sorry for the direct email bother.
>
> ---stack trace and code from within tomcat----
> ----code from within tomcat----
> System.setProperty("jdbc.drivers",
> "com.mysql.jdbc.Driver");
> GenericObjectPool connectionPool = new
> GenericObjectPool(null);
> ConnectionFactory connectionFactory = new
>
DriverManagerConnectionFactory("jdbc:mysql://10.117.7.18:3306/dow?autoReconn
ect=true",
> "user", "pass");
> connectionPool.setMaxActive(10);
> connectionPool.setMaxIdle(10);
> connectionPool.setMaxWait(10);
>
> PoolableConnectionFactory poolableConnectionFactory
> = new PoolableConnectionFactory(connectionFactory,
> connectionPool, null, null, false, true);
> PoolingDriver driver = new PoolingDriver();
> driver.registerPool("dow", connectionPool);
> Connection conn =
> DriverManager.getConnection("jdbc:apache:commons:dbcp:dow");
>
> ----stack trace of error--------
> org.apache.commons.dbcp.DbcpException:
> java.sql.SQLException: No suitable driver
>         at
>
org.apache.commons.dbcp.DriverManagerConnectionFactory.createConnection(Driv
erManagerConnectionFactory.java:101)
>         at
>
org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnect
ionFactory.java:184)
>         at
> org.apache.commons.pool.impl.GenericObjectPool.borrowObject(Unknown
> Source)
>         at
> org.apache.commons.dbcp.PoolingDriver.connect(PoolingDriver.java:146)
>         at
> java.sql.DriverManager.getConnection(DriverManager.java:512)
>         at
> java.sql.DriverManager.getConnection(DriverManager.java:194)
>         at
> com.cappsdigital.util.Manager.openConnection(Manager.java:60)
>         at
> com.cappsdigital.util.DbUtils.getStatement(DbUtils.java:30)
>         at
> com.cappsdigital.util.DbUtils.<clinit>(DbUtils.java:535)
>         at
> com.cappsdigital.databeans.Templates.read(Templates.java:29)
>         at
>
com.cappsdigital.actions.DisplayTemplateListAction.perform(DisplayTemplateLi
stAction.java:32)
>         at
> com.cappsdigital.actions.CDGController.callAction(CDGController.java:243)
>         at
> com.cappsdigital.actions.CDGController.service(CDGController.java:219)
>         at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>         at
>
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:247)
>         at
>
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:193)
>         at
>
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:260)
>         at
>
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:643)
>         at
>
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
>         at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
>         at
>
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:191)
>         at
>
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:643)
>         at
>
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase
.java:527)
>         at
>
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:641)
>         at
>
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
>         at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
>         at
> org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2396)
>         at
>
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180
)
>         at
>
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:643)
>       at
>
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.
java:170)
>         at
>
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:641)
>         at
>
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172
)
>         at
>
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:641)
>         at
>
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
>         at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
>         at
>
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
:174)
>         at
>
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:643)
>         at
>
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
>         at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
>         at
> org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
>         at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:405)
>         at
>
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConne
ction(Http11Protocol.java:380)
>         at
> org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:508)
>         at
>
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
a:533)
>         at java.lang.Thread.run(Thread.java:491)
>
> ---end trace---
>
> ---start stand alone, working code---
>
> import javax.sql.DataSource;
> import java.sql.*
> import org.apache.commons.pool.ObjectPool;
> import org.apache.commons.pool.impl.GenericObjectPool;
> import org.apache.commons.dbcp.*;
>
> public class poolingDataSourceExample {
>
>     public static void main(String[] args) throws
> Exception {
> String username = "user";
> String pwd = "passwd";
> String uri =
> "jdbc:mysql://10.117.7.18:3306/dow?autoReconnect=true";
> String myStmt = "SELECT * FROM USERS";
>         DataSource dataSource =
> setupDataSource(username, pwd, uri);
>
>         Connection conn = null;
>         Statement stmt = null;
>         ResultSet rset = null;
>
>         try {
>             conn = dataSource.getConnection(username,
> pwd);
>             stmt = conn.createStatement();
>             rset = stmt.executeQuery(myStmt);
>             int numcols =
> rset.getMetaData().getColumnCount();
>             while(rset.next()) {
>                 for(int i=1;i<=numcols;i++) {
>                     System.out.print("\t" +
> rset.getString(i));
>                 }
>                 System.out.println("");
>             }
>         } catch(SQLException e) {
>             e.printStackTrace();
>         } finally {
>             try { rset.close(); } catch(Exception e) {
> }
>             try { stmt.close(); } catch(Exception e) {
> }
>             try { conn.close(); } catch(Exception e) {
> }
>         }
>     }
>
>     public static DataSource setupDataSource(String
> uname, String pwd, String connectURI) throws Exception
> {
>         System.setProperty("jdbc.drivers",
> "com.mysql.jdbc.Driver");
>         ObjectPool connectionPool = new
> GenericObjectPool(null);
>
>         ConnectionFactory connectionFactory = new
> DriverManagerConnectionFactory(connectURI,uname, pwd);
>
>         PoolableConnectionFactory
> poolableConnectionFactory = new
>
PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,t
rue);
>         PoolingDataSource dataSource = new
> PoolingDataSource(connectionPool);
>
>         return dataSource;
>     }
> }
>
> ---end----
>
> cheers,
>
> Paul
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
>
James
-------
http://radio.weblogs.com/0112098/

__________________________________________________
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

Mime
View raw message