You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Diego Castillo <di...@inexbee.com> on 2001/12/14 10:18:58 UTC

MySQL DataSource using Tomcat 4

Hi all!

I have a JSP that must fetch some information from a MySQL database.
Everything works fine if I create manually a DataSource in my code:

  org.gjt.mm.mysql.MysqlDataSource pool =
    new org.gjt.mm.mysql.MysqlDataSource();
  pool.setServerName("localhost");
  pool.setPort(3306);
  pool.setDatabaseName("pim");


Now I would like Tomcat to create this DataSource object at start-up and
find it using JNDI ENC. My code looks like:

  InitialContext initialContext = new InitialContext();
  DataSource pool =
    (DataSource) initialContext.lookup("java:comp/env/jdbc/pim");


This code does find a DataSource object, but it seems that the object found
is not initialised. I have tried many different combinations for my
"server.xml" file, but it just looks impossible to figure out what the
problem is. The JDBC driver is below common/lib and I am using Tomcat in
standalone mode. My "server.xml" file looks like:

  <Context path="" docBase="pim" debug="0">
    <Resource name="jdbc/pim" auth="Container" type="javax.sql.DataSource"/>
    <ResourceParams name="jdbc/pim">
      <parameter>
        <name>driverClassName</name>
        <value>org.gjt.mm.mysql.MysqlDataSource</value>
      </parameter>
      <parameter>
        <name>driverName</name>
        <value>jdbc:mysql://localhost:3306/pim</value>
      </parameter>
    </ResourceParams>
  </Context>


Does anybody know what is happening? How do I instruct tyrex about the
factory it should use?


Any help would be welcome!


Diego Castillo


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


MySQL DataSource using Tomcat 4

Posted by Diego Castillo <di...@inexbee.com>.
Hello again,


I'm sorry for sending a second message on the same problem, but this is the
second day I am stuck with this problem.


I try to configure a DataSource to MySQL using Tomcat 4.0.1. The JNDI
binding is created, but the object found through the ENC is null (not
initialised). I use the following resource definition:


<Resource name="jdbc/pim" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/pim">
  <parameter>
    <name>driverClassName</name>
    <value>org.gjt.mm.mysql.MysqlDataSource</value>
  </parameter>
  <parameter>
    <name>driverName</name>
    <value>jdbc:mysql://localhost:3306/pim</value>
  </parameter>
</ResourceParams>


My database does not require any login/password. I manage to run my JSP on a
different servlet container: same code, same JNDI binding, same database,
same URL, etc.


Has anybody ever managed to create a pool to MySQL using Tomcat? Where can I
find some further documentation on the possible parameters to be used for
the ResourceParams tag? The standard documentation looks really insufficient
to me on this point...


Thanks for any help you can offer.




Diego


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


RE: MySQL DataSource using Tomcat 4

Posted by Diego Castillo <di...@inexbee.com>.
I found what was going wrong with my DataSource!

The configuration (server.xml + web.xml) was OK, and so was the code. But I
had put the jar file containing the driver in more than one place:
common/lib, server/lib, WEB-INF/lib...

I still don't understand why, but this certainly hurts. The class loader
must have something wrong which causes a ClassCastException when the jar
file is duplicated!

Now I have one single copy of my jar file and everything works fine. Thanks
to those who have help me with this problem.


Diego

-----Message d'origine-----
De : Diego Castillo [mailto:diego.castillo@inexbee.com]
Envoye : lundi 17 decembre 2001 12:34
A : Tomcat Users List
Objet : RE: MySQL DataSource using Tomcat 4


OK, now I think I'm getting it.

I have modified my server.xml file so that it includes a login/password that
permits connecting to the database:

<Resource name="jdbc/pim" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/pim">
  <parameter>
    <name>driverClassName</name>
    <value>org.gjt.mm.mysql.Driver</value>
  </parameter>
  <parameter>
    <name>driverName</name>
    <value>jdbc:mysql://localhost:3306/pim</value>
  </parameter>
  <parameter>
    <name>user</name>
    <value>diego</value>
  </parameter>
  <parameter>
    <name>password</name>
    <value>diego</value>
  </parameter>
<ResourceParams/>

This does not seem to improve things that much. What is really important is
using as driverClassName property the org.gjt.mm.mysql.Driver from MySQL. As
you said, Tyrex requires the driver, not the data source implementation.

Now I find a not null object using JNDI and get a default toString()
"Enabled DataSource" message. This object is of type
tyrex.jdbc.xa.EnabledDataSource according to the getClass().getName()
function. However I can not cast it to any type, this including both
javax.sql.DataSource and the tyrex.jdbc.xa.EnabledDataSource itself.

Can anybody understand this? Is the object incorrectly initialised?

I have put copies of the JDBC driver jar file in both /common/lib and
/server/lib directories...


Diego

-----Message d'origine-----
De : craigmcc@smtp2-in.lerelaisinternet.com
[mailto:craigmcc@smtp2-in.lerelaisinternet.com]De la part de Craig R.
McClanahan
Envoye : vendredi 14 decembre 2001 21:05
A : Tomcat Users List; diego.castillo@inexbee.com
Objet : RE: MySQL DataSource using Tomcat 4


The thing to remembert is that the ENC does *not* use MySQL's own
connection pool implementation -- it uses its own (Tyrex).  And Tyrex's
mechanism for connectiong to the database requires logging on with a
username and password.

Craig


On Fri, 14 Dec 2001, Diego Castillo wrote:

> Date: Fri, 14 Dec 2001 19:16:39 +0100
> From: Diego Castillo <di...@inexbee.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>,
>      diego.castillo@inexbee.com
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: RE: MySQL DataSource using Tomcat 4
>
> Hello Craig,
>
> Thanks for your answer. I have tried your suggestion, but I still have the
> same problem: the object I found using JNDI ENC is not initialised, it's
> null. This is normal because I have set up my MySQL database so that it
> requires no login/password for the moment.
>
> I am using the following resource definition:
> <Resource name="jdbc/pim" auth="Container" type="javax.sql.DataSource"/>
> <ResourceParams name="jdbc/pim">
>   <parameter>
>     <name>driverClassName</name>
>     <value>org.gjt.mm.mysql.MysqlDataSource</value>
>   </parameter>
>   <parameter>
>     <name>driverName</name>
>     <value>jdbc:mysql://localhost:3306/pim</value>
>   </parameter>
>   <parameter><name>user</name><value/></parameter>
>   <parameter><name>password</name><value/></parameter>
> </ResourceParams>
>
> I have read the JNDI How-To hundreds of times, but I am still missing
> something...
>
>
> Diego
>
> -----Message d'origine-----
> De : craigmcc@smtp2-in.lerelaisinternet.com
> [mailto:craigmcc@smtp2-in.lerelaisinternet.com]De la part de Craig R.
> McClanahan
> Envoye : vendredi 14 decembre 2001 18:40
> A : Tomcat Users List; diego.castillo@inexbee.com
> Objet : Re: MySQL DataSource using Tomcat 4
>
>
> You also need the database username and password (in the "user" and
> "password" parameters, respectively).  More info in the JNDI How-To, which
> is part of the docs shipped with Tomcat and also available online.
>
> http://jakarta.apache.org/tomcat/tomcat-4.0-doc/jndi-resources-howto.html
>
> Craig
>
>
> On Fri, 14 Dec 2001, Diego Castillo wrote:
>
> > Date: Fri, 14 Dec 2001 10:18:58 +0100
> > From: Diego Castillo <di...@inexbee.com>
> > Reply-To: Tomcat Users List <to...@jakarta.apache.org>,
> >      diego.castillo@inexbee.com
> > To: Tomcat Users List <to...@jakarta.apache.org>
> > Subject: MySQL DataSource using Tomcat 4
> >
> > Hi all!
> >
> > I have a JSP that must fetch some information from a MySQL database.
> > Everything works fine if I create manually a DataSource in my code:
> >
> >   org.gjt.mm.mysql.MysqlDataSource pool =
> >     new org.gjt.mm.mysql.MysqlDataSource();
> >   pool.setServerName("localhost");
> >   pool.setPort(3306);
> >   pool.setDatabaseName("pim");
> >
> >
> > Now I would like Tomcat to create this DataSource object at start-up and
> > find it using JNDI ENC. My code looks like:
> >
> >   InitialContext initialContext = new InitialContext();
> >   DataSource pool =
> >     (DataSource) initialContext.lookup("java:comp/env/jdbc/pim");
> >
> >
> > This code does find a DataSource object, but it seems that the object
> found
> > is not initialised. I have tried many different combinations for my
> > "server.xml" file, but it just looks impossible to figure out what the
> > problem is. The JDBC driver is below common/lib and I am using Tomcat in
> > standalone mode. My "server.xml" file looks like:
> >
> >   <Context path="" docBase="pim" debug="0">
> >     <Resource name="jdbc/pim" auth="Container"
> type="javax.sql.DataSource"/>
> >     <ResourceParams name="jdbc/pim">
> >       <parameter>
> >         <name>driverClassName</name>
> >         <value>org.gjt.mm.mysql.MysqlDataSource</value>
> >       </parameter>
> >       <parameter>
> >         <name>driverName</name>
> >         <value>jdbc:mysql://localhost:3306/pim</value>
> >       </parameter>
> >     </ResourceParams>
> >   </Context>
> >
> >
> > Does anybody know what is happening? How do I instruct tyrex about the
> > factory it should use?
> >
> >
> > Any help would be welcome!
> >
> >
> > Diego Castillo
> >
> >
> > --
> > To unsubscribe:   <ma...@jakarta.apache.org>
> > For additional commands: <ma...@jakarta.apache.org>
> > Troubles with the list: <ma...@jakarta.apache.org>
> >
> >
>
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


RE: MySQL DataSource using Tomcat 4

Posted by Diego Castillo <di...@inexbee.com>.
OK, now I think I'm getting it.

I have modified my server.xml file so that it includes a login/password that
permits connecting to the database:

<Resource name="jdbc/pim" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/pim">
  <parameter>
    <name>driverClassName</name>
    <value>org.gjt.mm.mysql.Driver</value>
  </parameter>
  <parameter>
    <name>driverName</name>
    <value>jdbc:mysql://localhost:3306/pim</value>
  </parameter>
  <parameter>
    <name>user</name>
    <value>diego</value>
  </parameter>
  <parameter>
    <name>password</name>
    <value>diego</value>
  </parameter>
<ResourceParams/>

This does not seem to improve things that much. What is really important is
using as driverClassName property the org.gjt.mm.mysql.Driver from MySQL. As
you said, Tyrex requires the driver, not the data source implementation.

Now I find a not null object using JNDI and get a default toString()
"Enabled DataSource" message. This object is of type
tyrex.jdbc.xa.EnabledDataSource according to the getClass().getName()
function. However I can not cast it to any type, this including both
javax.sql.DataSource and the tyrex.jdbc.xa.EnabledDataSource itself.

Can anybody understand this? Is the object incorrectly initialised?

I have put copies of the JDBC driver jar file in both /common/lib and
/server/lib directories...


Diego

-----Message d'origine-----
De : craigmcc@smtp2-in.lerelaisinternet.com
[mailto:craigmcc@smtp2-in.lerelaisinternet.com]De la part de Craig R.
McClanahan
Envoye : vendredi 14 decembre 2001 21:05
A : Tomcat Users List; diego.castillo@inexbee.com
Objet : RE: MySQL DataSource using Tomcat 4


The thing to remembert is that the ENC does *not* use MySQL's own
connection pool implementation -- it uses its own (Tyrex).  And Tyrex's
mechanism for connectiong to the database requires logging on with a
username and password.

Craig


On Fri, 14 Dec 2001, Diego Castillo wrote:

> Date: Fri, 14 Dec 2001 19:16:39 +0100
> From: Diego Castillo <di...@inexbee.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>,
>      diego.castillo@inexbee.com
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: RE: MySQL DataSource using Tomcat 4
>
> Hello Craig,
>
> Thanks for your answer. I have tried your suggestion, but I still have the
> same problem: the object I found using JNDI ENC is not initialised, it's
> null. This is normal because I have set up my MySQL database so that it
> requires no login/password for the moment.
>
> I am using the following resource definition:
> <Resource name="jdbc/pim" auth="Container" type="javax.sql.DataSource"/>
> <ResourceParams name="jdbc/pim">
>   <parameter>
>     <name>driverClassName</name>
>     <value>org.gjt.mm.mysql.MysqlDataSource</value>
>   </parameter>
>   <parameter>
>     <name>driverName</name>
>     <value>jdbc:mysql://localhost:3306/pim</value>
>   </parameter>
>   <parameter><name>user</name><value/></parameter>
>   <parameter><name>password</name><value/></parameter>
> </ResourceParams>
>
> I have read the JNDI How-To hundreds of times, but I am still missing
> something...
>
>
> Diego
>
> -----Message d'origine-----
> De : craigmcc@smtp2-in.lerelaisinternet.com
> [mailto:craigmcc@smtp2-in.lerelaisinternet.com]De la part de Craig R.
> McClanahan
> Envoye : vendredi 14 decembre 2001 18:40
> A : Tomcat Users List; diego.castillo@inexbee.com
> Objet : Re: MySQL DataSource using Tomcat 4
>
>
> You also need the database username and password (in the "user" and
> "password" parameters, respectively).  More info in the JNDI How-To, which
> is part of the docs shipped with Tomcat and also available online.
>
> http://jakarta.apache.org/tomcat/tomcat-4.0-doc/jndi-resources-howto.html
>
> Craig
>
>
> On Fri, 14 Dec 2001, Diego Castillo wrote:
>
> > Date: Fri, 14 Dec 2001 10:18:58 +0100
> > From: Diego Castillo <di...@inexbee.com>
> > Reply-To: Tomcat Users List <to...@jakarta.apache.org>,
> >      diego.castillo@inexbee.com
> > To: Tomcat Users List <to...@jakarta.apache.org>
> > Subject: MySQL DataSource using Tomcat 4
> >
> > Hi all!
> >
> > I have a JSP that must fetch some information from a MySQL database.
> > Everything works fine if I create manually a DataSource in my code:
> >
> >   org.gjt.mm.mysql.MysqlDataSource pool =
> >     new org.gjt.mm.mysql.MysqlDataSource();
> >   pool.setServerName("localhost");
> >   pool.setPort(3306);
> >   pool.setDatabaseName("pim");
> >
> >
> > Now I would like Tomcat to create this DataSource object at start-up and
> > find it using JNDI ENC. My code looks like:
> >
> >   InitialContext initialContext = new InitialContext();
> >   DataSource pool =
> >     (DataSource) initialContext.lookup("java:comp/env/jdbc/pim");
> >
> >
> > This code does find a DataSource object, but it seems that the object
> found
> > is not initialised. I have tried many different combinations for my
> > "server.xml" file, but it just looks impossible to figure out what the
> > problem is. The JDBC driver is below common/lib and I am using Tomcat in
> > standalone mode. My "server.xml" file looks like:
> >
> >   <Context path="" docBase="pim" debug="0">
> >     <Resource name="jdbc/pim" auth="Container"
> type="javax.sql.DataSource"/>
> >     <ResourceParams name="jdbc/pim">
> >       <parameter>
> >         <name>driverClassName</name>
> >         <value>org.gjt.mm.mysql.MysqlDataSource</value>
> >       </parameter>
> >       <parameter>
> >         <name>driverName</name>
> >         <value>jdbc:mysql://localhost:3306/pim</value>
> >       </parameter>
> >     </ResourceParams>
> >   </Context>
> >
> >
> > Does anybody know what is happening? How do I instruct tyrex about the
> > factory it should use?
> >
> >
> > Any help would be welcome!
> >
> >
> > Diego Castillo
> >
> >
> > --
> > To unsubscribe:   <ma...@jakarta.apache.org>
> > For additional commands: <ma...@jakarta.apache.org>
> > Troubles with the list: <ma...@jakarta.apache.org>
> >
> >
>
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


RE: MySQL DataSource using Tomcat 4

Posted by "Craig R. McClanahan" <cr...@apache.org>.
The thing to remembert is that the ENC does *not* use MySQL's own
connection pool implementation -- it uses its own (Tyrex).  And Tyrex's
mechanism for connectiong to the database requires logging on with a
username and password.

Craig


On Fri, 14 Dec 2001, Diego Castillo wrote:

> Date: Fri, 14 Dec 2001 19:16:39 +0100
> From: Diego Castillo <di...@inexbee.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>,
>      diego.castillo@inexbee.com
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: RE: MySQL DataSource using Tomcat 4
>
> Hello Craig,
>
> Thanks for your answer. I have tried your suggestion, but I still have the
> same problem: the object I found using JNDI ENC is not initialised, it's
> null. This is normal because I have set up my MySQL database so that it
> requires no login/password for the moment.
>
> I am using the following resource definition:
> <Resource name="jdbc/pim" auth="Container" type="javax.sql.DataSource"/>
> <ResourceParams name="jdbc/pim">
>   <parameter>
>     <name>driverClassName</name>
>     <value>org.gjt.mm.mysql.MysqlDataSource</value>
>   </parameter>
>   <parameter>
>     <name>driverName</name>
>     <value>jdbc:mysql://localhost:3306/pim</value>
>   </parameter>
>   <parameter><name>user</name><value/></parameter>
>   <parameter><name>password</name><value/></parameter>
> </ResourceParams>
>
> I have read the JNDI How-To hundreds of times, but I am still missing
> something...
>
>
> Diego
>
> -----Message d'origine-----
> De : craigmcc@smtp2-in.lerelaisinternet.com
> [mailto:craigmcc@smtp2-in.lerelaisinternet.com]De la part de Craig R.
> McClanahan
> Envoye : vendredi 14 decembre 2001 18:40
> A : Tomcat Users List; diego.castillo@inexbee.com
> Objet : Re: MySQL DataSource using Tomcat 4
>
>
> You also need the database username and password (in the "user" and
> "password" parameters, respectively).  More info in the JNDI How-To, which
> is part of the docs shipped with Tomcat and also available online.
>
> http://jakarta.apache.org/tomcat/tomcat-4.0-doc/jndi-resources-howto.html
>
> Craig
>
>
> On Fri, 14 Dec 2001, Diego Castillo wrote:
>
> > Date: Fri, 14 Dec 2001 10:18:58 +0100
> > From: Diego Castillo <di...@inexbee.com>
> > Reply-To: Tomcat Users List <to...@jakarta.apache.org>,
> >      diego.castillo@inexbee.com
> > To: Tomcat Users List <to...@jakarta.apache.org>
> > Subject: MySQL DataSource using Tomcat 4
> >
> > Hi all!
> >
> > I have a JSP that must fetch some information from a MySQL database.
> > Everything works fine if I create manually a DataSource in my code:
> >
> >   org.gjt.mm.mysql.MysqlDataSource pool =
> >     new org.gjt.mm.mysql.MysqlDataSource();
> >   pool.setServerName("localhost");
> >   pool.setPort(3306);
> >   pool.setDatabaseName("pim");
> >
> >
> > Now I would like Tomcat to create this DataSource object at start-up and
> > find it using JNDI ENC. My code looks like:
> >
> >   InitialContext initialContext = new InitialContext();
> >   DataSource pool =
> >     (DataSource) initialContext.lookup("java:comp/env/jdbc/pim");
> >
> >
> > This code does find a DataSource object, but it seems that the object
> found
> > is not initialised. I have tried many different combinations for my
> > "server.xml" file, but it just looks impossible to figure out what the
> > problem is. The JDBC driver is below common/lib and I am using Tomcat in
> > standalone mode. My "server.xml" file looks like:
> >
> >   <Context path="" docBase="pim" debug="0">
> >     <Resource name="jdbc/pim" auth="Container"
> type="javax.sql.DataSource"/>
> >     <ResourceParams name="jdbc/pim">
> >       <parameter>
> >         <name>driverClassName</name>
> >         <value>org.gjt.mm.mysql.MysqlDataSource</value>
> >       </parameter>
> >       <parameter>
> >         <name>driverName</name>
> >         <value>jdbc:mysql://localhost:3306/pim</value>
> >       </parameter>
> >     </ResourceParams>
> >   </Context>
> >
> >
> > Does anybody know what is happening? How do I instruct tyrex about the
> > factory it should use?
> >
> >
> > Any help would be welcome!
> >
> >
> > Diego Castillo
> >
> >
> > --
> > To unsubscribe:   <ma...@jakarta.apache.org>
> > For additional commands: <ma...@jakarta.apache.org>
> > Troubles with the list: <ma...@jakarta.apache.org>
> >
> >
>
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


RE: MySQL DataSource using Tomcat 4

Posted by Diego Castillo <di...@inexbee.com>.
Hello Craig,

Thanks for your answer. I have tried your suggestion, but I still have the
same problem: the object I found using JNDI ENC is not initialised, it's
null. This is normal because I have set up my MySQL database so that it
requires no login/password for the moment.

I am using the following resource definition:
<Resource name="jdbc/pim" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/pim">
  <parameter>
    <name>driverClassName</name>
    <value>org.gjt.mm.mysql.MysqlDataSource</value>
  </parameter>
  <parameter>
    <name>driverName</name>
    <value>jdbc:mysql://localhost:3306/pim</value>
  </parameter>
  <parameter><name>user</name><value/></parameter>
  <parameter><name>password</name><value/></parameter>
</ResourceParams>

I have read the JNDI How-To hundreds of times, but I am still missing
something...


Diego

-----Message d'origine-----
De : craigmcc@smtp2-in.lerelaisinternet.com
[mailto:craigmcc@smtp2-in.lerelaisinternet.com]De la part de Craig R.
McClanahan
Envoye : vendredi 14 decembre 2001 18:40
A : Tomcat Users List; diego.castillo@inexbee.com
Objet : Re: MySQL DataSource using Tomcat 4


You also need the database username and password (in the "user" and
"password" parameters, respectively).  More info in the JNDI How-To, which
is part of the docs shipped with Tomcat and also available online.

http://jakarta.apache.org/tomcat/tomcat-4.0-doc/jndi-resources-howto.html

Craig


On Fri, 14 Dec 2001, Diego Castillo wrote:

> Date: Fri, 14 Dec 2001 10:18:58 +0100
> From: Diego Castillo <di...@inexbee.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>,
>      diego.castillo@inexbee.com
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: MySQL DataSource using Tomcat 4
>
> Hi all!
>
> I have a JSP that must fetch some information from a MySQL database.
> Everything works fine if I create manually a DataSource in my code:
>
>   org.gjt.mm.mysql.MysqlDataSource pool =
>     new org.gjt.mm.mysql.MysqlDataSource();
>   pool.setServerName("localhost");
>   pool.setPort(3306);
>   pool.setDatabaseName("pim");
>
>
> Now I would like Tomcat to create this DataSource object at start-up and
> find it using JNDI ENC. My code looks like:
>
>   InitialContext initialContext = new InitialContext();
>   DataSource pool =
>     (DataSource) initialContext.lookup("java:comp/env/jdbc/pim");
>
>
> This code does find a DataSource object, but it seems that the object
found
> is not initialised. I have tried many different combinations for my
> "server.xml" file, but it just looks impossible to figure out what the
> problem is. The JDBC driver is below common/lib and I am using Tomcat in
> standalone mode. My "server.xml" file looks like:
>
>   <Context path="" docBase="pim" debug="0">
>     <Resource name="jdbc/pim" auth="Container"
type="javax.sql.DataSource"/>
>     <ResourceParams name="jdbc/pim">
>       <parameter>
>         <name>driverClassName</name>
>         <value>org.gjt.mm.mysql.MysqlDataSource</value>
>       </parameter>
>       <parameter>
>         <name>driverName</name>
>         <value>jdbc:mysql://localhost:3306/pim</value>
>       </parameter>
>     </ResourceParams>
>   </Context>
>
>
> Does anybody know what is happening? How do I instruct tyrex about the
> factory it should use?
>
>
> Any help would be welcome!
>
>
> Diego Castillo
>
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: MySQL DataSource using Tomcat 4

Posted by "Craig R. McClanahan" <cr...@apache.org>.
You also need the database username and password (in the "user" and
"password" parameters, respectively).  More info in the JNDI How-To, which
is part of the docs shipped with Tomcat and also available online.

http://jakarta.apache.org/tomcat/tomcat-4.0-doc/jndi-resources-howto.html

Craig


On Fri, 14 Dec 2001, Diego Castillo wrote:

> Date: Fri, 14 Dec 2001 10:18:58 +0100
> From: Diego Castillo <di...@inexbee.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>,
>      diego.castillo@inexbee.com
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: MySQL DataSource using Tomcat 4
>
> Hi all!
>
> I have a JSP that must fetch some information from a MySQL database.
> Everything works fine if I create manually a DataSource in my code:
>
>   org.gjt.mm.mysql.MysqlDataSource pool =
>     new org.gjt.mm.mysql.MysqlDataSource();
>   pool.setServerName("localhost");
>   pool.setPort(3306);
>   pool.setDatabaseName("pim");
>
>
> Now I would like Tomcat to create this DataSource object at start-up and
> find it using JNDI ENC. My code looks like:
>
>   InitialContext initialContext = new InitialContext();
>   DataSource pool =
>     (DataSource) initialContext.lookup("java:comp/env/jdbc/pim");
>
>
> This code does find a DataSource object, but it seems that the object found
> is not initialised. I have tried many different combinations for my
> "server.xml" file, but it just looks impossible to figure out what the
> problem is. The JDBC driver is below common/lib and I am using Tomcat in
> standalone mode. My "server.xml" file looks like:
>
>   <Context path="" docBase="pim" debug="0">
>     <Resource name="jdbc/pim" auth="Container" type="javax.sql.DataSource"/>
>     <ResourceParams name="jdbc/pim">
>       <parameter>
>         <name>driverClassName</name>
>         <value>org.gjt.mm.mysql.MysqlDataSource</value>
>       </parameter>
>       <parameter>
>         <name>driverName</name>
>         <value>jdbc:mysql://localhost:3306/pim</value>
>       </parameter>
>     </ResourceParams>
>   </Context>
>
>
> Does anybody know what is happening? How do I instruct tyrex about the
> factory it should use?
>
>
> Any help would be welcome!
>
>
> Diego Castillo
>
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>