• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Configuring mySQL database connectivity in tomcat's server.xml

 
Rakesh Rajmohan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello..

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,
Rakesh
 
Tim Holloway
Saloon Keeper
Posts: 18301
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic