This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to link my tomcat to mysql?

 
Moses Herrada
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys i need help connecting tomcat to mysql . At the console monitor they caught the ClassNotFoundException. Do i need to do any changes to the settings when i downloaded tomcat and mysql?
thx
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This page in Tomcat's documentation shows you line for line how to set up a JNDI datasource for mysql.

http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-datasource-examples-howto.html
 
Ben Keeping
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I expect your ClassNotFoundException is thrown because you have not added the mysql JDBC driver to TOMCAT_HOME/common/lib .
Download it from here : http://www.mysql.com/products/connector/j/
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Other Ben,
Without knowing how he's trying to connect, we can't really tell him the best place to put his driver libraries. If he is using the container managed connection pool, then yes, he should put them in common/lib. If he's shipping his own connection pool or creating the connections himself, he would be much better off putting the library under WEB-INF/lib in his own application so it can be moved around as a single war file.

Moses,
If, after you decide which route you want to take, you run into any more problems, you'll probably get more help in the Tomcat list as this isn't really a general JDBC issue.

Good-Luck,
-Ben
 
Moses Herrada
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thx guys i think i got it
 
Ben Keeping
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Other Ben :
I have to disagree there - the OP said they were trying to connect to mysql from within the tomcat container. IMO, this kind of JDBC connectivity is common, and so probably used from many webapps (in theory), and so the easiest way to achive that is to dump the driver jar into common/lib - this makes it accessible to the container, any 3rd party pool that is running inside that container, and webapps. Its very rare that you have multiple driver versions, so common/lib is the best place - just put it in, and forget about it. Even better would be to place it in JAVA_HOME/jre/lib/ext, but I didn't want to confuse the issue !
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Other Ben:

We may have to agree to disagree. Since version 2.2 the servlet spec has been pushing the concept of self-contained, pluggable applications. Other than resources managed by the container, a web app should be packed with everything it needs to run. There should be no unnecessary reliance on outside dependencies.

The following is an exerpt from an article written by Jason Hunter (whom I think we all can agree is widely recognized as an authority in the field).
Source:
http://www.javaworld.com/javaworld/jw-10-1999/jw-10-servletapi_p.html

<excerpt>
Web applications
Java Servlet API 2.2 includes one new feature so significant it may change the way the Web works. That feature: Web applications.


A Web application, as defined in the servlet specification, is a collection of servlets, JavaServer Pages (JSPs), HTML documents, images, and other Web resources that are set up in such a way as to be portably deployed across any servlet-enabled Web server. Installing a Web app is simple. Gone are the days of detailed instruction sheets telling you how to install third-party Web components, with different instructions for each type of Web server. With Web apps, the entire application can be contained in a single archive file and deployed by placing the file into a specific directory.
</excerpt>


All this being said, I do have to admit that, except for some limited cases, using a Java database like hsql, you're always going to have to do some configuration to connect your app to a database and driver versioning is a double edged sword that cut into both of our arguments. I could pack a driver that is incompatible with the version of the RDBMS, you could have the wrong version (or multiple versions) in common/lib. Still, I think the principal of self-contained apps is a good one and I would rather err in that direction.

-Ben
[ January 22, 2005: Message edited by: Ben Souther ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic