File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes Configuring mySQL database connectivity in tomcat's server.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Configuring mySQL database connectivity in tomcat Watch "Configuring mySQL database connectivity in tomcat New topic

Configuring mySQL database connectivity in tomcat's server.xml

Rakesh Rajmohan

Joined: Jul 09, 2009
Posts: 22

I read in an article that we can configure any database connectivity by just configuring it in server.xml, so my questions here are..

1) is it the best way to configure database connectivity (or) we have any other best way (if so please tell me how)

2) If I am configuring it through Tomcat's server.xml, will the connectivity only be persistent to JSP pages or even to any of my normal Java classes..?

Thanks in advance,
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

Tomcat has the ability to construct resource object and make them locatable via JNDI. I've used this for a lot of things, but one of the most common is a database connection pool. Tomcat comes with a copy of the Apache DBCP pooler, although if you prefer, you can plug in other poolers.

For details on how to construct and configure a pool, check out Tomcat's documentation. I think it includes an example for MySQL.

Once the pool has been created, the webapp can use JNDI to locate it - for example as "java:/comp/env/jdbc/datasource1". Any Java class can do a JNDI lookup and get a connection from that pool, and since JSPs compile into servlets and servlets are java classes...

Personally, I don't recommend putting logic on JSPs. They can very swiftly become real maintenance nightmares. However, if you must, there are some JSP tags that will help. I think the JSTL tagset includes some, as a matter of fact.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Configuring mySQL database connectivity in tomcat's server.xml
It's not a secret anymore!