Hi Harry,

I've been trying to setup my mySQL connection to tomcat as well and
has
been reading a lot of documents on how to do this.  I think I'm getting
more
confused.

I've setup my params as you suggested below.  When I ran my sample
app, I got the following exception:

javax.naming.NoInitialContextException: Need to specify class name in
environment or system property, or as an applet parameter, or in an
application resoure file: 
   java.naming.factory.initial
         at javax.naming.spi.NamingManager.getInitialContext<unknown
source>
         at javax.naming.InitialContext.getDefaultInitCtx<unknown
source>
         at javax.naming.InitialContext.getURLOrDefaultInitCtx<unknown
source>
         at javax.naming.InitialContext.lookup<unknown source>
         at
com.maxis.app.ContentProcessor.main<ContentProcessor.java:34>

Here's my code:
Context ctx = new InitialContext();
Context evtCtx = (Context) ctx.lookup("java:comp/env");
DataSource ds = (DataSource) evtCtx.lookup("jdbc/mySQLDatabase");
---> in my web.xml : <res-ref-name>jdbc/mySQLDatabase</res-ref-name>
---> in my server.xml: <ResourceParams name="jdbc/mySQLDatabase">

Any ideas???

Thanks,
--Kawthar

>>> [EMAIL PROTECTED] 10/03/2004 08:05:03 PM >>>
Hi Dave

Sorry for my long absence - I was away from my computer for while.

I think Doug's last message just about says it all in respect of
connection
pools. Follow his advice to use the Tomcat How-Tos exactly as they are,
and
you should be okay.

I looked through your code - the stuff you originally posted following
my
suggestion to do so - and I did spot one crucial mistake.

This line in your test JSP:


    DataSource ds = ( DataSource ) ctx.lookup("java:comp/env/jdbc/MyDS"
);


Should read:


    DataSource ds = ( DataSource )
ctx.lookup("java:comp/env/jdbc/mysql" );


Spot the difference? :-)

The "jdbc/mysql" context refers to the name given to the resource in
the
context.xml:


    Resource name="jdbc/mysql"
           type="com.mysql.jdbc.jdbc2..."
           auth="Container"/>


I would also urge you to go back to using the Commons DBCP resources,
and
specifying the "jdbc/mysql" resource as in the Tomcat How-To - namely,
this
definition:


    <Resource 
     name="jdbc/mysql"
    
type="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource"
     auth="Container"/>


Should read:


    <Resource 
     name="jdbc/mysql"
     auth="Container"
     type="javax.sql.DataSource"/>


And this ResourceParams element:


    <parameter>
        <name>factory</name>
        <value>
            com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory
        </value>
    </parameter>


Should read:


    <parameter>
        <name>factory</name>
        <value>
            org.apache.commons.dbcp.BasicDataSourceFactory
        </value>
    </parameter>


Stick to the Tomcat How-Tos, using the Commons DBCP package, at least
until
you get the thing working, and then you can switch if you want.

Finally, just a suggestion, but I would specify the minimum possible
for the
'url' attribute:


    <parameter>
        <name>url</name>
        <value>
            jdbc:mysql://localhost:3306/DATABASE
        </value>
    </parameter>


Keep it simple, to start with :-) because it could just be one of
those
non-essential parameters is causing the thing to break.

Good luck!

Harry



>> Despite my posting - and I really hope someone chips in concerning
the
>> question I raised about the <resource-ref> being redundant in the
deployment
>> descriptor (!) - the first thing to say is, have faith!
>> 
>> Connection pooling works, and it is actually quite simple, so do not
give up
>> on it.
> 
> Cheers for the advice Harry... here's where I'm at....
> 
> I have no choice on the giving up side of things, need to implement
it
> for some client code I'm working on
> 
> ;-)
> 
> I've been doing a lot of googling to try and get answers so I may
have
> got crossed wires, I had a version working (or thinking it was
working)
> with the info in $JAKARTA_HOME/conf/server.xml but I wasn't happy
with
> this solution (preferring to have the connection defined in
> $JAKARTA_HOME/conf/Catalina/localhost/<app_name>.xml for good
reasons...
> 
> so I'm basically restarting and I now have the following config
> 
> $JAKARTA_HOME/conf/Catalina/localhost/<app_name>.xml
> 
> <?xml version='1.0' encoding='utf-8'?>
> <Context docBase="dev-sstl" path="/dev-sstl" reloadable="true"
> useNaming="false">
> 
> <Resource
> name="jdbc/mysql"
> type="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource"
> auth="Container"/>
> <ResourceParams name="jdbc/mysql">
> <parameter>
> <name>factory</name>
> <value>com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory</value>
> </parameter>
> <parameter>
> <name>port</name>
> <value>3306</value>
> </parameter>
> <parameter>
> <name>user</name>
> <value>USERNAME</value>
> </parameter>
> <parameter>
> <name>password</name>
> <value>PASSWORD</value>
> </parameter>
> <parameter>
> <name>serverName</name>
> <value>localhost</value>
> </parameter>
> <parameter>
> <name>databaseName</name>
> <value>DATABASE</value>
> </parameter>
> <parameter>
> <name>explicitUrl</name>
> <value>true</value>
> </parameter>
> <parameter>
> <name>url</name>
>
<value>jdbc:mysql://localhost:3306/DATABASE?autoReconnect=true&amp;useUnicode=
>
true&amp;characterEncoding=UTF8&amp;max-connections=50&amp;min-connections=2&a
> mp;inactivity-timeout=30&amp;wait-timeout=30</value>
> </parameter>
> </ResourceParams>
> </Context>
> 
> The info for the above i gleaned from
> http://www.russellbeattie.com/notebook/1006529.html 
> 
> Then in <web_app>/WEB-INF/web.xml I have
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <web-app xmlns="http://java.sun.com/xml/ns/j2ee";
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
> http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"; version="2.4">
> 
> <resource-ref>
> <description>DB connection</description>
> <res-ref-name>jdbc/mysql</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Container</res-auth>
> </resource-ref>
> </web-app>
> 
> Then in my test JSP I have
> try {
> Context ctx = new InitialContext();
> DataSource ds = ( DataSource ) ctx.lookup("java:comp/env/jdbc/MyDS"
);
> Connection conn = ds.getConnection();
> ...
> 
> And the error I get is
> 
> javax.servlet.ServletException: Name java:comp is not bound in this
> Context
> 
> Which is an error I've managed to hit several times, I know the
whole
> connection pooling is the right way to go about this, just surprised
at
> how long it is taking me to get going (I dread to think what it will
be
> like installing this live with the client, but I'll save that happy
> thought for later)
> 
> As ever any help much appreciated... (and if the person who helps me
to
> get this working is ever in London I'll stand them a beer or 3)
> 
> ;-)
> 
> TIA
> Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED] 
For additional commands, e-mail: [EMAIL PROTECTED] 

Confidential information may be contained in this e-mail and any files transmitted 
with it ('Message'). If you are not the addressee indicated in this Message (or 
responsible for delivery of this Message to such person), you are hereby notified that 
any dissemination, distribution, printing or copying of this Message or any part 
thereof is strictly prohibited. In such a case, you should delete this Message 
immediately and advise the sender by return e-mail. Opinions, conclusions and other 
information in this Message that do not relate to the official business of Maxis shall 
be understood as neither given nor endorsed by Maxis.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to