You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Prem Padarath <pp...@gmail.com> on 2007/07/23 20:51:49 UTC

MySql Connector returning ?DataSource

Hi,

I am trying to set up a database resource in Tomcat 5.5.20 .  I am having a
problem getting a DataSource object back from a JNDI lookup.
(I am getting a "org.apache.tomcat.dbcp.dbcp.BasicDataSource" object
returned and throwing an exception - code below)

My problem is similar to the "Re: MySql Connector" thread of messages.

I can see the resource listed in the Tomcat Administration Tool under Tomcat
Server --> Service --> Host --> Context(/dbtest)
and all the information for the datasource looks fine (as from the
context.xml file below).

My context.xml file (placed in my webapp under META-INF) looks as follows:

<Context crossContext="true" path="/dbtest" reloadable="true">
<Logger className="org.apache.catalina.logger.FileLogger"
    prefix="localhost-dbtest-log."
    suffix="txt"
    timestamp="true"/>

          <Resource
            name="jdbc/MYSQLDS"
            auth="Container"
            type="javax.sql.DataSource"
            maxActive="5"
            maxIdle="3"
            maxWait="10000"
            username="myuser"
            password="mypwd"
            driverClassName="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3306/testdb"/>
          <WatchedResource>WEB-INF/web.xml</WatchedResource>
        </Context>

My web.xml file contains the following:

    <resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/MYSQLDS</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>


And the snippet/code I am using to acquire a datasource is as follows:

DataSource ds = null;
....
ds = (DataSource)initContext.lookup("java:/comp/env/jdbc/MYSQLDS");
....

When the app is run, I get back

java.lang.Exception: org.apache.tomcat.dbcp.dbcp.BasicDataSource
    dbtest.HelloWorld.execute(HelloWorld.java:53)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke (
DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:585)

(by the way, I am running this within a Struts2 Framework)

Can anyone tell me what I am doing incorrectly still?

Thx,
Prem

Re: MySql Connector returning ?DataSource

Posted by Prem Padarath <pp...@gmail.com>.
Hi Chris,

> o.a.t.d.d.BasicDataSource implements javax.sql.DataSource. What's the
> problem?

The problem is that whatever is returned from the lookup call is causing an
exception.  I tested what is coming back and it is an o.a.t.d.d.B.D.S and it
is putting it to a DataSource.

The stack trace follows:

SEVERE: Could not execute action
java.lang.RuntimeException: helloCould not create resource factory instance
    at dbtest.HelloWorld.execute(HelloWorld.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(
DefaultActionInvocation.java:408)
    at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(
DefaultActionInvocation.java:262)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:224)
    at
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(
DefaultWorkflowInterceptor.java:213)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept
(MethodFilterInterceptor.java:86)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:219)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:218)
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
UtilTimerStack.java:455)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:216)
    at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(
ValidationInterceptor.java:115)
    at
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept
(AnnotationValidationInterceptor.java:48)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept
(MethodFilterInterceptor.java:86)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:219)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:218)
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
UtilTimerStack.java:455)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:216)
    at
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(
ConversionErrorInterceptor.java:123)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:219)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:218)
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
UtilTimerStack.java:455)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:216)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.intercept(
ParametersInterceptor.java:161)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:219)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:218)
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
UtilTimerStack.java:455)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:216)
    at
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(
StaticParametersInterceptor.java:105)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:219)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:218)
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
UtilTimerStack.java:455)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:216)
    at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(
CheckboxInterceptor.java:83)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:219)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:218)
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
UtilTimerStack.java:455)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:216)
    at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(
FileUploadInterceptor.java:207)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:219)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:218)
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
UtilTimerStack.java:455)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:216)
    at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(
ModelDrivenInterceptor.java:74)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:219)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:218)
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
UtilTimerStack.java:455)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:216)
    at
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(
ScopedModelDrivenInterceptor.java:127)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:219)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:218)
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
UtilTimerStack.java:455)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:216)
    at
org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(
ProfilingActivationInterceptor.java:107)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:219)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:218)
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
UtilTimerStack.java:455)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:216)
    at
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(
DebuggingInterceptor.java:206)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:219)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:218)
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
UtilTimerStack.java:455)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:216)
    at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(
ChainingInterceptor.java:115)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:219)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:218)
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
UtilTimerStack.java:455)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:216)
    at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(
I18nInterceptor.java:143)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:219)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:218)
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
UtilTimerStack.java:455)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:216)
    at com.opensymphony.xwork2.interceptor.PrepareInterceptor.intercept(
PrepareInterceptor.java:115)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:219)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:218)
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
UtilTimerStack.java:455)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:216)
    at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(
ServletConfigInterceptor.java:170)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:219)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:218)
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
UtilTimerStack.java:455)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:216)
    at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(
AliasInterceptor.java:123)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:219)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:218)
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
UtilTimerStack.java:455)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:216)
    at
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(
ExceptionMappingInterceptor.java:176)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:219)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:218)
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
UtilTimerStack.java:455)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:216)
    at org.apache.struts2.impl.StrutsActionProxy$1.call(
StrutsActionProxy.java:46)
    at org.apache.struts2.impl.StrutsActionProxy$1.call(
StrutsActionProxy.java:45)
    at org.apache.struts2.impl.RequestContextImpl.callInContext(
RequestContextImpl.java:172)
    at org.apache.struts2.impl.StrutsActionProxy.execute(
StrutsActionProxy.java:44)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(
Dispatcher.java:507)
    at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(
FilterDispatcher.java:421)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(
ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(
StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(
StandardContextValve.java:178)
    at org.apache.catalina.core.StandardHostValve.invoke(
StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(
ErrorReportValve.java:105)
    at org.apache.catalina.core.StandardEngineValve.invoke(
StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(
CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:869)
    at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection
(Http11BaseProtocol.java:664)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(
PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(
LeaderFollowerWorkerThread.java:80)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(
ThreadPool.java:684)
    at java.lang.Thread.run(Thread.java:595)
Caused by: javax.naming.NamingException: Could not create resource factory
instance [Root exception is java.lang.ClassCastException:
org.apache.tomcat.dbcp.dbcp.BasicDataSource]
    at org.apache.naming.factory.ResourceFactory.getObjectInstance(
ResourceFactory.java:101)
    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java
:304)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:792)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:139)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:780)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:139)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:780)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:139)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:780)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:136)
    at javax.naming.InitialContext.lookup(InitialContext.java:351)
    at dbtest.HelloWorld.execute(HelloWorld.java:33)
    ... 115 more
Caused by: java.lang.ClassCastException:
org.apache.tomcat.dbcp.dbcp.BasicDataSource
    at org.apache.naming.factory.ResourceFactory.getObjectInstance(
ResourceFactory.java:97)
    ... 127 more


Prem

On 7/23/07, Christopher Schultz <ch...@christopherschultz.net> wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Prem,
>
> Prem Padarath wrote:
> > I am trying to set up a database resource in Tomcat 5.5.20 .  I am
> having a
> > problem getting a DataSource object back from a JNDI lookup.
> > (I am getting a "org.apache.tomcat.dbcp.dbcp.BasicDataSource" object
> > returned and throwing an exception - code below)
>
> o.a.t.d.d.BasicDataSource implements javax.sql.DataSource. What's the
> problem?
>
> > My context.xml file (placed in my webapp under META-INF) looks as
> follows:
> >
> > <Context crossContext="true" path="/dbtest" reloadable="true">
>
> Remove the "path" attribute, please. It is unlikely to be causing
> problems, but you should definitely take it out.
>
> >          <Resource
> >            name="jdbc/MYSQLDS"
> >            auth="Container"
> >            type="javax.sql.DataSource"
> >            driverClassName="com.mysql.jdbc.Driver"
> >            url="jdbc:mysql://localhost:3306/testdb"/>
>
> This looks fine.
>
> > My web.xml file contains the following:
> >
> >    <resource-ref>
> >      <description>DB Connection</description>
> >      <res-ref-name>jdbc/MYSQLDS</res-ref-name>
> >      <res-type>javax.sql.DataSource</res-type>
> >      <res-auth>Container</res-auth>
> >  </resource-ref>
>
> I have found that <resource-ref> is superfluous when using a
> context-defined DataSource. I'm not sure if that's the way it's supposed
> to be, but I have found that this doesn't matter.
>
> > And the snippet/code I am using to acquire a datasource is as follows:
> >
> > DataSource ds = null;
> > ....
> > ds = (DataSource)initContext.lookup("java:/comp/env/jdbc/MYSQLDS");
>
> Looks good to me.
>
> > When the app is run, I get back
> >
> > java.lang.Exception: org.apache.tomcat.dbcp.dbcp.BasicDataSource
> >    dbtest.HelloWorld.execute(HelloWorld.java:53)
> >    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >    sun.reflect.NativeMethodAccessorImpl.invoke(
> > NativeMethodAccessorImpl.java:39)
> >    sun.reflect.DelegatingMethodAccessorImpl.invoke (
> > DelegatingMethodAccessorImpl.java:25)
> >    java.lang.reflect.Method.invoke(Method.java:585)
>
> Can you give us the full stack trace? All I see is reflection code in
> there. Is there a message? java.lang.Exception is just a little less
> useful than getting a java.lang.Throwable.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFGpQTx9CaO5/Lv0PARAhfCAJ9B3Hkd1lra9+Dd9+4ysqu2w90ZfgCeOlq3
> I/uYB+efFUY6lLrnYA38Zf0=
> =6foU
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: MySql Connector returning ?DataSource

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Prem,

Prem Padarath wrote:
> I am trying to set up a database resource in Tomcat 5.5.20 .  I am having a
> problem getting a DataSource object back from a JNDI lookup.
> (I am getting a "org.apache.tomcat.dbcp.dbcp.BasicDataSource" object
> returned and throwing an exception - code below)

o.a.t.d.d.BasicDataSource implements javax.sql.DataSource. What's the
problem?

> My context.xml file (placed in my webapp under META-INF) looks as follows:
> 
> <Context crossContext="true" path="/dbtest" reloadable="true">

Remove the "path" attribute, please. It is unlikely to be causing
problems, but you should definitely take it out.

>          <Resource
>            name="jdbc/MYSQLDS"
>            auth="Container"
>            type="javax.sql.DataSource"
>            driverClassName="com.mysql.jdbc.Driver"
>            url="jdbc:mysql://localhost:3306/testdb"/>

This looks fine.

> My web.xml file contains the following:
> 
>    <resource-ref>
>      <description>DB Connection</description>
>      <res-ref-name>jdbc/MYSQLDS</res-ref-name>
>      <res-type>javax.sql.DataSource</res-type>
>      <res-auth>Container</res-auth>
>  </resource-ref>

I have found that <resource-ref> is superfluous when using a
context-defined DataSource. I'm not sure if that's the way it's supposed
to be, but I have found that this doesn't matter.

> And the snippet/code I am using to acquire a datasource is as follows:
> 
> DataSource ds = null;
> ....
> ds = (DataSource)initContext.lookup("java:/comp/env/jdbc/MYSQLDS");

Looks good to me.

> When the app is run, I get back
> 
> java.lang.Exception: org.apache.tomcat.dbcp.dbcp.BasicDataSource
>    dbtest.HelloWorld.execute(HelloWorld.java:53)
>    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>    sun.reflect.NativeMethodAccessorImpl.invoke(
> NativeMethodAccessorImpl.java:39)
>    sun.reflect.DelegatingMethodAccessorImpl.invoke (
> DelegatingMethodAccessorImpl.java:25)
>    java.lang.reflect.Method.invoke(Method.java:585)

Can you give us the full stack trace? All I see is reflection code in
there. Is there a message? java.lang.Exception is just a little less
useful than getting a java.lang.Throwable.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGpQTx9CaO5/Lv0PARAhfCAJ9B3Hkd1lra9+Dd9+4ysqu2w90ZfgCeOlq3
I/uYB+efFUY6lLrnYA38Zf0=
=6foU
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: MySql Connector returning ?DataSource

Posted by Prem Padarath <pp...@gmail.com>.
Chuck,

Checked...it is only in the one place.

Thx,
Prem

On 7/23/07, Caldarale, Charles R <Ch...@unisys.com> wrote:
>
> > From: Prem Padarath [mailto:ppadarath@gmail.com]
> > Subject: Re: MySql Connector returning ?DataSource
> >
> > I checked.  The mysql jar file is in common\lib directory!
>
> Is it also in the webapp's WEB-INF/lib directory?  Having it in two
> places at once can cause all sorts of interesting problems.
>
> - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: MySql Connector returning ?DataSource

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chuck,

Caldarale, Charles R wrote:
>> From: Prem Padarath [mailto:ppadarath@gmail.com] 
>> Subject: Re: MySql Connector returning ?DataSource
>>
>> I checked.  The mysql jar file is in common\lib directory!
> 
> Is it also in the webapp's WEB-INF/lib directory?  Having it in two
> places at once can cause all sorts of interesting problems.

I'll bet this is the problem. It's odd, though, since the exception is:

Caused by: java.lang.ClassCastException:
org.apache.tomcat.dbcp.dbcp.BasicDataSource
   at org.apache.naming.factory.ResourceFactory.getObjectInstance(
ResourceFactory.java:97)

Here's the code in question:

                if (factoryClass != null) {
                    try {
// line 97             factory = (ObjectFactory)
// line 97 cont'd                 factoryClass.newInstance();
                    } catch (Throwable t) {
                        if (t instanceof NamingException)
                            throw (NamingException) t;
                        NamingException ex = new NamingException
                            ("Could not create resource factory
                             instance");
                        ex.initCause(t);
                        throw ex;
                    }
                }

For some reason, his ObjectFactory isn't an ObjectFactory... it's a
BasicDataSource.

Prem, have you put any Tomcat-related JAR files into your WEB-INF/lib
directory?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGpSrM9CaO5/Lv0PARAoPUAJ0Xl9GGATFzREuXwvl/CFaWjkBSrwCgmuR/
OaZxzNwC6nlnpVIfHn7XSZo=
=eEfQ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: MySql Connector returning ?DataSource

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Prem Padarath [mailto:ppadarath@gmail.com] 
> Subject: Re: MySql Connector returning ?DataSource
> 
> I checked.  The mysql jar file is in common\lib directory!

Is it also in the webapp's WEB-INF/lib directory?  Having it in two
places at once can cause all sorts of interesting problems.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: MySql Connector returning ?DataSource

Posted by Prem Padarath <pp...@gmail.com>.
David,

I checked.  The mysql jar file is in common\lib directory!
I think my test app (direct access) would have had to have retrieved the
jdbc classes from the Tomcat lib as I didn't include them in the war file.

Thx,
Prem

On 7/23/07, David Smith <dn...@cornell.edu> wrote:
>
> This could easily be caused by the mysql jar file not being in tomcat's
> common/lib directory -- especially if local, non JNDI access is working.
>
> --David
>
> Prem Padarath wrote:
> > Hi Wade,
> >
> > Yes, I have been able to connect with a plain java class and I have been
> > able to connect from within Struts2 directly.  It is when I try to get a
> > DataSource object from Tomcat's JNDI that it messes.
> >
> > Prem
> >
> > On 7/23/07, Wade Chandler <hw...@yahoo.com> wrote:
> >>
> >> From a JSP page try to make a MYSQL connection using
> >> just pure JDBC calls. It may be something to do with
> >> your JDBC classes and the directory your JAR files are
> >> housed. If I remember correctly I had to put my MYSQL
> >> JAR file in the shared folder so the server could
> >> access them. This versus having them in the
> >> WEB-INF/lib folder. May or may not be your issue, but
> >> make sure you can actually make a JDBC connection with
> >> the drivers first. If not then the DataSource won't
> >> work either.
> >>
> >> I have never used
> >> <WatchedResource>WEB-INF/web.xml</WatchedResource>
> >>
> >> before either. Maybe comment out this line and see if
> >> it has any impact.
> >>
> >> Wade
> >>
> >> --- Prem Padarath <pp...@gmail.com> wrote:
> >>
> >> > Hi,
> >> >
> >> > I am trying to set up a database resource in Tomcat
> >> > 5.5.20 .  I am having a
> >> > problem getting a DataSource object back from a JNDI
> >> > lookup.
> >> > (I am getting a
> >> > "org.apache.tomcat.dbcp.dbcp.BasicDataSource" object
> >> > returned and throwing an exception - code below)
> >> >
> >> > My problem is similar to the "Re: MySql Connector"
> >> > thread of messages.
> >> >
> >> > I can see the resource listed in the Tomcat
> >> > Administration Tool under Tomcat
> >> > Server --> Service --> Host --> Context(/dbtest)
> >> > and all the information for the datasource looks
> >> > fine (as from the
> >> > context.xml file below).
> >> >
> >> > My context.xml file (placed in my webapp under
> >> > META-INF) looks as follows:
> >> >
> >> > <Context crossContext="true" path="/dbtest"
> >> > reloadable="true">
> >> > <Logger
> >> > className="org.apache.catalina.logger.FileLogger"
> >> >     prefix="localhost-dbtest-log."
> >> >     suffix="txt"
> >> >     timestamp="true"/>
> >> >
> >> >           <Resource
> >> >             name="jdbc/MYSQLDS"
> >> >             auth="Container"
> >> >             type="javax.sql.DataSource"
> >> >             maxActive="5"
> >> >             maxIdle="3"
> >> >             maxWait="10000"
> >> >             username="myuser"
> >> >             password="mypwd"
> >> >             driverClassName="com.mysql.jdbc.Driver"
> >> >
> >> > url="jdbc:mysql://localhost:3306/testdb"/>
> >> >
> >> > <WatchedResource>WEB-INF/web.xml</WatchedResource>
> >> >         </Context>
> >> >
> >> > My web.xml file contains the following:
> >> >
> >> >     <resource-ref>
> >> >       <description>DB Connection</description>
> >> >       <res-ref-name>jdbc/MYSQLDS</res-ref-name>
> >> >       <res-type>javax.sql.DataSource</res-type>
> >> >       <res-auth>Container</res-auth>
> >> >   </resource-ref>
> >> >
> >> >
> >> > And the snippet/code I am using to acquire a
> >> > datasource is as follows:
> >> >
> >> > DataSource ds = null;
> >> > ....
> >> > ds =
> >> >
> >> (DataSource)initContext.lookup("java:/comp/env/jdbc/MYSQLDS");
> >> > ....
> >> >
> >> > When the app is run, I get back
> >> >
> >> > java.lang.Exception:
> >> > org.apache.tomcat.dbcp.dbcp.BasicDataSource
> >> >     dbtest.HelloWorld.execute(HelloWorld.java:53)
> >> >
> >> > sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> >> > Method)
> >> >     sun.reflect.NativeMethodAccessorImpl.invoke(
> >> > NativeMethodAccessorImpl.java:39)
> >> >     sun.reflect.DelegatingMethodAccessorImpl.invoke
> >> > (
> >> > DelegatingMethodAccessorImpl.java:25)
> >> >     java.lang.reflect.Method.invoke(Method.java:585)
> >> >
> >> > (by the way, I am running this within a Struts2
> >> > Framework)
> >> >
> >> > Can anyone tell me what I am doing incorrectly
> >> > still?
> >> >
> >> > Thx,
> >> > Prem
> >> >
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To start a new topic, e-mail: users@tomcat.apache.org
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: MySql Connector returning ?DataSource

Posted by David Smith <dn...@cornell.edu>.
This could easily be caused by the mysql jar file not being in tomcat's 
common/lib directory -- especially if local, non JNDI access is working.

--David

Prem Padarath wrote:
> Hi Wade,
>
> Yes, I have been able to connect with a plain java class and I have been
> able to connect from within Struts2 directly.  It is when I try to get a
> DataSource object from Tomcat's JNDI that it messes.
>
> Prem
>
> On 7/23/07, Wade Chandler <hw...@yahoo.com> wrote:
>>
>> From a JSP page try to make a MYSQL connection using
>> just pure JDBC calls. It may be something to do with
>> your JDBC classes and the directory your JAR files are
>> housed. If I remember correctly I had to put my MYSQL
>> JAR file in the shared folder so the server could
>> access them. This versus having them in the
>> WEB-INF/lib folder. May or may not be your issue, but
>> make sure you can actually make a JDBC connection with
>> the drivers first. If not then the DataSource won't
>> work either.
>>
>> I have never used
>> <WatchedResource>WEB-INF/web.xml</WatchedResource>
>>
>> before either. Maybe comment out this line and see if
>> it has any impact.
>>
>> Wade
>>
>> --- Prem Padarath <pp...@gmail.com> wrote:
>>
>> > Hi,
>> >
>> > I am trying to set up a database resource in Tomcat
>> > 5.5.20 .  I am having a
>> > problem getting a DataSource object back from a JNDI
>> > lookup.
>> > (I am getting a
>> > "org.apache.tomcat.dbcp.dbcp.BasicDataSource" object
>> > returned and throwing an exception - code below)
>> >
>> > My problem is similar to the "Re: MySql Connector"
>> > thread of messages.
>> >
>> > I can see the resource listed in the Tomcat
>> > Administration Tool under Tomcat
>> > Server --> Service --> Host --> Context(/dbtest)
>> > and all the information for the datasource looks
>> > fine (as from the
>> > context.xml file below).
>> >
>> > My context.xml file (placed in my webapp under
>> > META-INF) looks as follows:
>> >
>> > <Context crossContext="true" path="/dbtest"
>> > reloadable="true">
>> > <Logger
>> > className="org.apache.catalina.logger.FileLogger"
>> >     prefix="localhost-dbtest-log."
>> >     suffix="txt"
>> >     timestamp="true"/>
>> >
>> >           <Resource
>> >             name="jdbc/MYSQLDS"
>> >             auth="Container"
>> >             type="javax.sql.DataSource"
>> >             maxActive="5"
>> >             maxIdle="3"
>> >             maxWait="10000"
>> >             username="myuser"
>> >             password="mypwd"
>> >             driverClassName="com.mysql.jdbc.Driver"
>> >
>> > url="jdbc:mysql://localhost:3306/testdb"/>
>> >
>> > <WatchedResource>WEB-INF/web.xml</WatchedResource>
>> >         </Context>
>> >
>> > My web.xml file contains the following:
>> >
>> >     <resource-ref>
>> >       <description>DB Connection</description>
>> >       <res-ref-name>jdbc/MYSQLDS</res-ref-name>
>> >       <res-type>javax.sql.DataSource</res-type>
>> >       <res-auth>Container</res-auth>
>> >   </resource-ref>
>> >
>> >
>> > And the snippet/code I am using to acquire a
>> > datasource is as follows:
>> >
>> > DataSource ds = null;
>> > ....
>> > ds =
>> >
>> (DataSource)initContext.lookup("java:/comp/env/jdbc/MYSQLDS");
>> > ....
>> >
>> > When the app is run, I get back
>> >
>> > java.lang.Exception:
>> > org.apache.tomcat.dbcp.dbcp.BasicDataSource
>> >     dbtest.HelloWorld.execute(HelloWorld.java:53)
>> >
>> > sun.reflect.NativeMethodAccessorImpl.invoke0(Native
>> > Method)
>> >     sun.reflect.NativeMethodAccessorImpl.invoke(
>> > NativeMethodAccessorImpl.java:39)
>> >     sun.reflect.DelegatingMethodAccessorImpl.invoke
>> > (
>> > DelegatingMethodAccessorImpl.java:25)
>> >     java.lang.reflect.Method.invoke(Method.java:585)
>> >
>> > (by the way, I am running this within a Struts2
>> > Framework)
>> >
>> > Can anyone tell me what I am doing incorrectly
>> > still?
>> >
>> > Thx,
>> > Prem
>> >
>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: MySql Connector returning ?DataSource

Posted by Prem Padarath <pp...@gmail.com>.
Hi Wade,

Yes, I have been able to connect with a plain java class and I have been
able to connect from within Struts2 directly.  It is when I try to get a
DataSource object from Tomcat's JNDI that it messes.

Prem

On 7/23/07, Wade Chandler <hw...@yahoo.com> wrote:
>
> From a JSP page try to make a MYSQL connection using
> just pure JDBC calls. It may be something to do with
> your JDBC classes and the directory your JAR files are
> housed. If I remember correctly I had to put my MYSQL
> JAR file in the shared folder so the server could
> access them. This versus having them in the
> WEB-INF/lib folder. May or may not be your issue, but
> make sure you can actually make a JDBC connection with
> the drivers first. If not then the DataSource won't
> work either.
>
> I have never used
> <WatchedResource>WEB-INF/web.xml</WatchedResource>
>
> before either. Maybe comment out this line and see if
> it has any impact.
>
> Wade
>
> --- Prem Padarath <pp...@gmail.com> wrote:
>
> > Hi,
> >
> > I am trying to set up a database resource in Tomcat
> > 5.5.20 .  I am having a
> > problem getting a DataSource object back from a JNDI
> > lookup.
> > (I am getting a
> > "org.apache.tomcat.dbcp.dbcp.BasicDataSource" object
> > returned and throwing an exception - code below)
> >
> > My problem is similar to the "Re: MySql Connector"
> > thread of messages.
> >
> > I can see the resource listed in the Tomcat
> > Administration Tool under Tomcat
> > Server --> Service --> Host --> Context(/dbtest)
> > and all the information for the datasource looks
> > fine (as from the
> > context.xml file below).
> >
> > My context.xml file (placed in my webapp under
> > META-INF) looks as follows:
> >
> > <Context crossContext="true" path="/dbtest"
> > reloadable="true">
> > <Logger
> > className="org.apache.catalina.logger.FileLogger"
> >     prefix="localhost-dbtest-log."
> >     suffix="txt"
> >     timestamp="true"/>
> >
> >           <Resource
> >             name="jdbc/MYSQLDS"
> >             auth="Container"
> >             type="javax.sql.DataSource"
> >             maxActive="5"
> >             maxIdle="3"
> >             maxWait="10000"
> >             username="myuser"
> >             password="mypwd"
> >             driverClassName="com.mysql.jdbc.Driver"
> >
> > url="jdbc:mysql://localhost:3306/testdb"/>
> >
> > <WatchedResource>WEB-INF/web.xml</WatchedResource>
> >         </Context>
> >
> > My web.xml file contains the following:
> >
> >     <resource-ref>
> >       <description>DB Connection</description>
> >       <res-ref-name>jdbc/MYSQLDS</res-ref-name>
> >       <res-type>javax.sql.DataSource</res-type>
> >       <res-auth>Container</res-auth>
> >   </resource-ref>
> >
> >
> > And the snippet/code I am using to acquire a
> > datasource is as follows:
> >
> > DataSource ds = null;
> > ....
> > ds =
> >
> (DataSource)initContext.lookup("java:/comp/env/jdbc/MYSQLDS");
> > ....
> >
> > When the app is run, I get back
> >
> > java.lang.Exception:
> > org.apache.tomcat.dbcp.dbcp.BasicDataSource
> >     dbtest.HelloWorld.execute(HelloWorld.java:53)
> >
> > sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > Method)
> >     sun.reflect.NativeMethodAccessorImpl.invoke(
> > NativeMethodAccessorImpl.java:39)
> >     sun.reflect.DelegatingMethodAccessorImpl.invoke
> > (
> > DelegatingMethodAccessorImpl.java:25)
> >     java.lang.reflect.Method.invoke(Method.java:585)
> >
> > (by the way, I am running this within a Struts2
> > Framework)
> >
> > Can anyone tell me what I am doing incorrectly
> > still?
> >
> > Thx,
> > Prem
> >
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: MySql Connector returning ?DataSource

Posted by Wade Chandler <hw...@yahoo.com>.
>From a JSP page try to make a MYSQL connection using
just pure JDBC calls. It may be something to do with
your JDBC classes and the directory your JAR files are
housed. If I remember correctly I had to put my MYSQL
JAR file in the shared folder so the server could
access them. This versus having them in the
WEB-INF/lib folder. May or may not be your issue, but
make sure you can actually make a JDBC connection with
the drivers first. If not then the DataSource won't
work either.

I have never used
<WatchedResource>WEB-INF/web.xml</WatchedResource>

before either. Maybe comment out this line and see if
it has any impact.

Wade

--- Prem Padarath <pp...@gmail.com> wrote:

> Hi,
> 
> I am trying to set up a database resource in Tomcat
> 5.5.20 .  I am having a
> problem getting a DataSource object back from a JNDI
> lookup.
> (I am getting a
> "org.apache.tomcat.dbcp.dbcp.BasicDataSource" object
> returned and throwing an exception - code below)
> 
> My problem is similar to the "Re: MySql Connector"
> thread of messages.
> 
> I can see the resource listed in the Tomcat
> Administration Tool under Tomcat
> Server --> Service --> Host --> Context(/dbtest)
> and all the information for the datasource looks
> fine (as from the
> context.xml file below).
> 
> My context.xml file (placed in my webapp under
> META-INF) looks as follows:
> 
> <Context crossContext="true" path="/dbtest"
> reloadable="true">
> <Logger
> className="org.apache.catalina.logger.FileLogger"
>     prefix="localhost-dbtest-log."
>     suffix="txt"
>     timestamp="true"/>
> 
>           <Resource
>             name="jdbc/MYSQLDS"
>             auth="Container"
>             type="javax.sql.DataSource"
>             maxActive="5"
>             maxIdle="3"
>             maxWait="10000"
>             username="myuser"
>             password="mypwd"
>             driverClassName="com.mysql.jdbc.Driver"
>            
> url="jdbc:mysql://localhost:3306/testdb"/>
>          
> <WatchedResource>WEB-INF/web.xml</WatchedResource>
>         </Context>
> 
> My web.xml file contains the following:
> 
>     <resource-ref>
>       <description>DB Connection</description>
>       <res-ref-name>jdbc/MYSQLDS</res-ref-name>
>       <res-type>javax.sql.DataSource</res-type>
>       <res-auth>Container</res-auth>
>   </resource-ref>
> 
> 
> And the snippet/code I am using to acquire a
> datasource is as follows:
> 
> DataSource ds = null;
> ....
> ds =
>
(DataSource)initContext.lookup("java:/comp/env/jdbc/MYSQLDS");
> ....
> 
> When the app is run, I get back
> 
> java.lang.Exception:
> org.apache.tomcat.dbcp.dbcp.BasicDataSource
>     dbtest.HelloWorld.execute(HelloWorld.java:53)
>    
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)
>     sun.reflect.NativeMethodAccessorImpl.invoke(
> NativeMethodAccessorImpl.java:39)
>     sun.reflect.DelegatingMethodAccessorImpl.invoke
> (
> DelegatingMethodAccessorImpl.java:25)
>     java.lang.reflect.Method.invoke(Method.java:585)
> 
> (by the way, I am running this within a Struts2
> Framework)
> 
> Can anyone tell me what I am doing incorrectly
> still?
> 
> Thx,
> Prem
> 


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org