Forums Register Login

How to link my tomcat to mysql?

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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/
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
thx guys i think i got it
+Pie Number of slices to send: Send
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 !
+Pie Number of slices to send: Send
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 ]
rubbery bacon. rubbery tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 805 times.
Similar Threads
mysql driver
how can i make tomcat and apache and mysql work together?what need downloaded ?how to
The max input fields for servlet can handle
how can i make tomcat and apache and mysql work together?what need downloaded ?how to
What is Connection pool?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:03:01.