• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Tomcat with MySQL Connection Pool

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!
I am having difficulty setting up a connection pool from Tomcat 4 to a MySQL database using the MM.MySQL driver version 2.0.12 found at SourceForge.net. Essentially, if you've done this before, I would like to see your entries in server.xml that pertain to the connection pool. (And any other code/config/etc. that you use).
BTW: I want to use DataSource objects and Tomcat's JNDI.
Thanks!
[ April 23, 2002: Message edited by: Jeff Wisard ]
 
Ranch Hand
Posts: 209
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've difficulty doing that too..
I've set it up successfully once. But not this time. However, here's the general attempts.
Here's my entries.

Store your mm.mysql.jar in /common directory.
WEB.XML file

Please tell me if u get it working.
Chu
 
Justin Chu
Ranch Hand
Posts: 209
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Correction:
store your mm.mysql.jar in /common/lib directory
My test.jsp file

I keep getting null for my DataSource.
I followed this exact steps on my last installation, and works. Maybe I'm missing something.
 
Jeff Wisard
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I'll try it and get back to you.
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried breaking out the Context lookup from the resource lookup? It shouldn't matter, but if nothing else works, why not try it? Stranger things have been the cause of trouble.

The added advantage of this approach, is that once you have c, you can look up everything else, since all JNDI resources should be rooted at java:comp/env

Also.. make sure your mysql connection URI has the appropriate port number after 'localhost' 3306 seemed to be a popular choice on google
 
Jeff Wisard
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I haven't been able to get this to work yet. I'm stuck. I've read all I can find about setting this up with Tomcat and followed the instructions very carefully....it just doesn't work. My DataSource object always ends up being null...
Any help from anyone would be greatly appreciated.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeff, have you tried writing a very small stand-alone java application that can test your JDBC driver URL, and by doing so, you also test the database install, and the way you are programming JDBC?
 
Jeff Wisard
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I have. In fact, I have FORM based authentication working with Tomcat through the same driver to database tables in the same database.
I am also able to create a connection using DriverManager through a jsp page.
The only thing that I can't get to work is obtaining a DataSource object through Tomcat's JNDI tree. Like I said, I have followed the Tomcat documentation (several times)...I am either missing something or their docs are in error (or both). Maybe something is wrong with the driver...
Have you tried this yet? (using the mm.MySql driver)
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't tried using DataSources in Tomcat actually, but I googled.

Here is one in Korean that has screenshots of the code
http://www.superuser.co.kr/jsp/kenu/page45.htm

The only other 'good' hit was unfortunately a problem post with no resolution. And wouldn't you know it? They guy hid his email, so you can't even email him to see if he solved it
http://www.geocrawler.com/lists/3/Databases/193/0/8291588/
 
Justin Chu
Ranch Hand
Posts: 209
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
did u solve this problem yet?
I used 2 jdbc drivers, Sybase and MySQL, Sybase seemed to work fine, while MySQL returns null.
Chu
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Correct me if i'm wrong, but don't you have to bind a specific connection pool implementation instance to the JNDI before attenpting to obtain pooled connections?
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Mr Wisard,
I have this particular case working at home.
This is what I have done in order to use connection pooling with Tomcat Version 4.*
Right before the </host> tag in your server.xml file include the following xml code:

After this is done you will also need to put a little xml sniplet in your web.xml file that pertains to the WebApp that you are using. The following code is below:

The above following needs to be defined after your servlet mapping. I believe order does mater for the WebApp Spec.
Finally use the following code in order to access a connection in Tomcat's pool

I got a book from the JavaRanch Giveway that I would highly recommend entitled Professional Apache Tomcat by Wrox
email me if you have any questions on this because I probably will forget about this thread.
[email protected]
I believe my jar file is either located in my common/lib or shared/lib directory.
Cheers,
Ryan
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Mr. Wishard,
Here's the solution to your problem.
Please set naming property to "true" through tomcat administration in your web application context.
Contect me on [email protected] if problem persist.
- Dipak Mehta
 
Ranch Hand
Posts: 309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i am also facing the problem of getting null for the datasource. i followed exactly the same steps as outlined here
tomcat page.
I am using tomcat5 and mysql driver version 3.0.8
What is missing ??
Thank you,
SHankar.
 
dipak mehta
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

The problem which I was faced is same... null datasource.
I found in my case that "useNaming" must be set to "true"... by setting it my problem get solved.
Please have a look at below context entry, you can see that useNaming=true is there.
If you are not familiar with tomcat administration console, you can directly edit your context entry in server.xml file.
<Context className="org.apache.catalina.core.StandardContext" cachingAllowed="true" charsetMapperClass="org.apache.catalina.util.CharsetMapper" cookies="true" crossContext="false" debug="0" docBase="/MyApp" mapperClass="org.apache.catalina.core.StandardContextMapper" path="/MyApp" privileged="false" reloadable="true" swallowOutput="false" useNaming="true" wrapperClass="org.apache.catalina.core.StandardWrapper">
Let me know if still problem persist.
 
reply
    Bookmark Topic Watch Topic
  • New Topic