Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Whahoo! Following its_toasted's recipes I have successfully implemented, successively, both Tomcat managed Database pooling and Hibernate Managed Database pooling. I did have a couple of issues to fix when implementing Hibernate managed pooling: 1) Order of entries into the xml. I first simply appended the database connection and pooling properties to my existing hibernate,cfg.xml. Wrong! The mapping element must come AFTER the property elements to conform to the dtd. 2) I had to comment out the datasource property for the configuration to work. Its-toated referred to this porblem in the context of Tomcat managed pooling, but I had no problem with it there. I did have problems with that issue when configuring the Hibernate managed pooling. I have included here the hibernate.cfg.xml that works for me. Note the datasource property commented out. hibernate-configuration session-factory !-- property name=connection.datasourcejava:comp/env/jdbc/CSRapp/property -- property name=show.sqlfalse/property property name=dialectorg.hibernate.dialect.MySQLDialect/property !-- Database connection information -- property name=connection.driver_classcom.mysql.jdbc.Driver/property property name=connection.urljdbc:mysql://localhost:3306/CSRapp/property property name=connection.usernameCSRapp/property property name=connection.passwordCSRapp/property !-- Connection pool parameters -- property name=connection_provider_classorg.hibernate.connection.CP30ConnectionProvider/property property name=c3p0.minPoolSize4/property property name=c3p0.timeout5000/property !-- Mapping files -- mapping resource=org/bcs/server/utils/ServiceProvider.hbm.xml/ /session-factory /hibernate-configuration Wanting my database configuration tightly coupled to my application, the Hibernate managed approach works best for me. Thank you all for a great job and great help. Caldarale, Charles R wrote: From: its_toas...@yahoo.com [mailto:its_toas...@yahoo.com] Subject: Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver PS - I just hacked together the Hibernate-controlled database connection / pooling on a freshly installed Tomcat 6.0.20. It works as advertised. A very comprehensive and useful writeup; thanks. Please consider adding the Hibernate-controlled pooling description to the Tomcat FAQ/Wiki Database section - or at least a pointer to the relevant Hibernate doc. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
very thorough analysis hopefully quick question on location of mysql libraries Tomcat managed database connections: Requires the MySQL connectors to be in $CATALINA_HOME/lib Hibernate managed database connections: Based on the above, you'll need to place the MySQL connection jar in your WEB-INF/lib directory. any reason why Tomcat managed DB connection would not read mysql jars located in WEB-INF/lib? thanks again Martin Gainty __ Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen. Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni. Date: Mon, 20 Jul 2009 19:56:32 -0700 From: its_toas...@yahoo.com Subject: Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver To: users@tomcat.apache.org --- On Mon, 7/20/09, David Smith d...@cornell.edu wrote: From: David Smith d...@cornell.edu Subject: Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver To: Tomcat Users List users@tomcat.apache.org Date: Monday, July 20, 2009, 6:16 PM Caldarale, Charles R wrote: From: David Smith [mailto:d...@cornell.edu] Subject: Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver This configuration is using a tomcat managed database pool. Put your mysql jar file in tomcat's lib folder and you'll see the error go away. But the stated intent is to use C3P0 pooling, rather than Tomcat's pooling; in that case, the Resource element must be removed and instead configured via whatever mechanism C3P0 wants. Can't have both. - Chuck No argument here. I'm just diagnosing the current issue. If the OP wants help with C3PO, that should be the configuration we are given. --David Late to the thread, and this is probably overkill. This is my understanding concerning how the Tomcat / Hibernate / database environment works. Your mileage may vary, and I will probably be corrected by some people on the list. Please note that I've only used Tomcat managed database pooling. Tomcat Managed Database Pooling === Anyway, here is my environment. OS - Fedora 10 === jdk/jre - 1.6.0_14 Tomcat- 6.0.20 MySQL - 5.0.77-1 IDE - NetBeans 6.7 Hibernate - 3.2.5.ga (provided with NetBeans) OS- Windows/XP Professional SP 3 === jdk/jre - 1.6.0_14 Tomcat- 6.0.20 MySQL - 5.1.31 IDE - NetBeans 6.7 Hibernate - 3.2.5.ga (provided with NetBeans) I've chosen to use Tomcat's database pooling for the NetBeans DVD Store tutorial sample application. This necessitates several changes in how the application is configured. Basics == 1. Per Tomcat documentation, I've placed mysql-connector-java-5.0.8-bin.jar in Tomcat's lib directory. This makes it available to Tomcat in order to set up database pooling 2. All Hibernate jars are located in WEB-INF/lib. NetBeans builds the war file correctly, so I don't have to copy any jar files around. Web Application === This also follows the Tomcat documentation for creating Tomcat-managed connection pooling. 1. In META-INF/context.xml: ?xml version=1.0 encoding=UTF-8? Context antiJARLocking=true path=/DVDStore Resource auth=Container driverClassName=com.mysql.jdbc.Driver maxActive=30 maxIdle=10 maxWait=1 name=jdbc/sakila password=* type=javax.sql.DataSource url=jdbc:mysql://localhost/sakila username=*/ /Context Obviously, replace the asterisks with the appropriate username and password. Replace the database url with your appropriate database. 2. In WEB-INF/web.xml: resource-ref descriptionThis is a MySQL database connection/description res-ref-namejdbc/sakila/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth
Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Take a look at http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html. Then consider that tomcat's database pooling is instantiated in tomcat's internal classes which do not have access to any webapp's WEB-INF/lib folder. The driver has to be visible to both tomcat's internal classes and the individual webapps, so it's best placed in tomcat's lib folder (or common/lib for older versions of tomcat). --David Martin Gainty wrote: very thorough analysis hopefully quick question on location of mysql libraries Tomcat managed database connections: Requires the MySQL connectors to be in $CATALINA_HOME/lib Hibernate managed database connections: Based on the above, you'll need to place the MySQL connection jar in your WEB-INF/lib directory. any reason why Tomcat managed DB connection would not read mysql jars located in WEB-INF/lib? thanks again Martin Gainty __ Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen. Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni. Date: Mon, 20 Jul 2009 19:56:32 -0700 From: its_toas...@yahoo.com Subject: Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver To: users@tomcat.apache.org --- On Mon, 7/20/09, David Smith d...@cornell.edu wrote: From: David Smith d...@cornell.edu Subject: Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver To: Tomcat Users List users@tomcat.apache.org Date: Monday, July 20, 2009, 6:16 PM Caldarale, Charles R wrote: From: David Smith [mailto:d...@cornell.edu] Subject: Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver This configuration is using a tomcat managed database pool. Put your mysql jar file in tomcat's lib folder and you'll see the error go away. But the stated intent is to use C3P0 pooling, rather than Tomcat's pooling; in that case, the Resource element must be removed and instead configured via whatever mechanism C3P0 wants. Can't have both. - Chuck No argument here. I'm just diagnosing the current issue. If the OP wants help with C3PO, that should be the configuration we are given. --David Late to the thread, and this is probably overkill. This is my understanding concerning how the Tomcat / Hibernate / database environment works. Your mileage may vary, and I will probably be corrected by some people on the list. Please note that I've only used Tomcat managed database pooling. Tomcat Managed Database Pooling === Anyway, here is my environment. OS - Fedora 10 === jdk/jre - 1.6.0_14 Tomcat- 6.0.20 MySQL - 5.0.77-1 IDE - NetBeans 6.7 Hibernate - 3.2.5.ga (provided with NetBeans) OS- Windows/XP Professional SP 3 === jdk/jre - 1.6.0_14 Tomcat- 6.0.20 MySQL - 5.1.31 IDE - NetBeans 6.7 Hibernate - 3.2.5.ga (provided with NetBeans) I've chosen to use Tomcat's database pooling for the NetBeans DVD Store tutorial sample application. This necessitates several changes in how the application is configured. Basics == 1. Per Tomcat documentation, I've placed mysql-connector-java-5.0.8-bin.jar in Tomcat's lib directory. This makes it available to Tomcat in order to set up database pooling 2. All Hibernate jars are located in WEB-INF/lib. NetBeans builds the war file correctly, so I don't have to copy any jar files around. Web Application === This also follows the Tomcat documentation for creating Tomcat-managed connection pooling. 1. In META-INF/context.xml: ?xml version=1.0 encoding=UTF-8? Context antiJARLocking=true path=/DVDStore Resource auth=Container driverClassName=com.mysql.jdbc.Driver maxActive=30 maxIdle=10 maxWait=1 name=jdbc/sakila
RE: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
this is good information many thanks for the link Martin Gainty __ Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni. Date: Tue, 21 Jul 2009 10:54:09 -0400 From: d...@cornell.edu To: users@tomcat.apache.org Subject: Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver Take a look at http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html. Then consider that tomcat's database pooling is instantiated in tomcat's internal classes which do not have access to any webapp's WEB-INF/lib folder. The driver has to be visible to both tomcat's internal classes and the individual webapps, so it's best placed in tomcat's lib folder (or common/lib for older versions of tomcat). --David Martin Gainty wrote: very thorough analysis hopefully quick question on location of mysql libraries Tomcat managed database connections: Requires the MySQL connectors to be in $CATALINA_HOME/lib Hibernate managed database connections: Based on the above, you'll need to place the MySQL connection jar in your WEB-INF/lib directory. any reason why Tomcat managed DB connection would not read mysql jars located in WEB-INF/lib? thanks again Martin Gainty __ Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen. Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni. Date: Mon, 20 Jul 2009 19:56:32 -0700 From: its_toas...@yahoo.com Subject: Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver To: users@tomcat.apache.org --- On Mon, 7/20/09, David Smith d...@cornell.edu wrote: From: David Smith d...@cornell.edu Subject: Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver To: Tomcat Users List users@tomcat.apache.org Date: Monday, July 20, 2009, 6:16 PM Caldarale, Charles R wrote: From: David Smith [mailto:d...@cornell.edu] Subject: Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver This configuration is using a tomcat managed database pool. Put your mysql jar file in tomcat's lib folder and you'll see the error go away. But the stated intent is to use C3P0 pooling, rather than Tomcat's pooling; in that case, the Resource element must be removed and instead configured via whatever mechanism C3P0 wants. Can't have both. - Chuck No argument here. I'm just diagnosing the current issue. If the OP wants help with C3PO, that should be the configuration we are given. --David Late to the thread, and this is probably overkill. This is my understanding concerning how the Tomcat / Hibernate / database environment works. Your mileage may vary, and I will probably be corrected by some people on the list. Please note that I've only used Tomcat managed database pooling. Tomcat Managed Database Pooling === Anyway, here is my
Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
You are right ... it shouldn't be put there. One thing you didn't seem to mention is how you are using your mysql driver. Are you trying to use the built-in database pooling? If that's the case, the mysql driver should be in tomcat's lib directory because tomcat's internals need access to it as well. Also can you offer some detail about your use of hibernate? If it's in your webapp, it should easily see the driver jar file. If it's in another webapp, it won't. --David Bob Marcum wrote: I have been experiencing java.lang.ClassNotFoundException: com.mysql.jdbc.Driver when attempting to run my webapp under tomcat 6.0.18. I have run my application successfully before under prior versions of Tomcat. I have found and implemented a solution that works, but I believe it is a wrong solution and I want to provoke some discussion about a right solution. Let me explain: My environment: Tomcat 6.0.18 jse 1.6.0_05 using hibernate 3.0 using mySQL standard-4.1.14 My development environment is driven by Ant 1.6.5 and ... irrelevant to the issue but ... my front end code is Google Web Toolkit (GWT) based. Now ... I kept getting mysql driver class not found at runtime. I have the driver mysql-connector-java-3.1.10-bin.jar file in myapp/WEB-INF/lib. I would have thought that would have solved the problem in a nice, tidy fashion, but it did not. After further investigation of the Tomcat 6 class loading mechanism I found this bit of information: ...plus classes and resources in JAR files under the /WEB-INF/lib directory of your web application archive, are made visible to the containing web application, but to no others. I believe I am being caught on that but to no others phrase. That would mean code directly in my app could see all the jar files in WEB-INF/lib but hibernate code, for instance, could not ?? !! even though conceptually the hibernate code is configured to be an integral part of my app ?? A solution I found to work is to copy the mysql-connector-java-3.1.10-bin.jar file into my jseHOME/jre/lib/ext directory. Now my app can see the driver at runtime just fine. But ... that seems a wrong solution to me. A right solution would bundle access to that jar file into the configuration of my webapp, which is what I expect and get when I put library jar files in WEB-INF/lib. Is there a more right solution that allows me to keep the library jar files for the mysql driver more closely bundled with my app, rather than force it to be seen be all users of java se 1.6.0_05?? ... and still meet the requirements of Tomcat's class loading mechanisms? Thanks. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
From: Bob Marcum [mailto:bmar...@bcscomputers.com] Subject: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver That would mean code directly in my app could see all the jar files in WEB-INF/lib but hibernate code, for instance, could not ?? !! Depends on where the Hibernate jar is located. If you've put that in the webapp's WEB-INF/lib directory, you shouldn't have a problem. If you've placed the Hibernate jar in some other location, you will need to put the MySQL jar in the same place. A solution I found to work is to copy the mysql-connector-java-3.1.10- bin.jar file into my jseHOME/jre/lib/ext directory. Be very, very careful if you copy jars - in this case you want to move it, not copy it. Having the same jar in multiple locations on a given branch of the classloading tree will result in never ending errors. If your Hibernate jar is in jre/lib/ext, then, it's likely you will have to put the MySQL jar there. The Hibernate jar really belongs with your webapp, not in any more global location. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Responding to both ... Being guided by your judgements I have made a few adjustements and re-tried. 1. I removed the mysql driver jar from my jse/jre/lib/ext 2. I confirmed hibernate3.jar is in myapp/WEB-INF/lib. It has always been there. 3. I put mysql-connector-java-3.1.10-bin.jar back into WEB-INF/lib 4. I did a find scan of my system, looking for other copies of both hibernate3.jar and mysql-connector-java-3.1.10-bin.jar to confirm there are no other copies which could be in classpath. I found no other copies which could be in classpath, given the tools I am using. well ... wait. There is a link to the mysql driver jar in hibernate-3.0's own lib directory. H. I wonder if that could be confusing hibernate? Since it is a link, I must have put it there a year or so ago. I did not remove the link. 5. I re-built the war file and re-deployed. 6. When I re-run the application, I am right back where I was. I get java.lang.ClassNotFoundException: com.mysql.jdbc.Driver. My webapp cannot see the mysql driver jar, although it clearly sees the hibernate jar. Hibernate code is what is running and attempting to load the driver. Suggestions, gents? David Smith wrote: You are right ... it shouldn't be put there. One thing you didn't seem to mention is how you are using your mysql driver. Are you trying to use the built-in database pooling? If that's the case, the mysql driver should be in tomcat's lib directory because tomcat's internals need access to it as well. I expect to use C3P0 pooling. I have the c3p0-0.8.5.2.jar in WEB-INF/lib. My understanding is that Hibernate will use C3P0 if it finds the c3p0 jar in classpath. However, I haven't really detailed the pooling, other than setting a configuration for the pooling: maxActive=10 maxWait=5000 maxIdle=4 I would expect to detail pooling as a later optimization once I have everything else working. Also can you offer some detail about your use of hibernate? If it's in your webapp, it should easily see the driver jar file. If it's in another webapp, it won't. The hibernate3.jar is in WEB-INF/lib, so based on the comments by both of you the application should see it, but it doesn't. See below. --David Caldarale, Charles R wrote: From: Bob Marcum [mailto:bmar...@bcscomputers.com] Subject: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver That would mean code directly in my app could see all the jar files in WEB-INF/lib but hibernate code, for instance, could not ?? !! Depends on where the Hibernate jar is located. If you've put that in the webapp's WEB-INF/lib directory, you shouldn't have a problem. If you've placed the Hibernate jar in some other location, you will need to put the MySQL jar in the same place. hibernate3.jar is in WEB-INF/lib and has always been there. A solution I found to work is to copy the mysql-connector-java-3.1.10- bin.jar file into my jseHOME/jre/lib/ext directory. Be very, very careful if you copy jars - in this case you want to move it, not copy it. Having the same jar in multiple locations on a given branch of the classloading tree will result in never ending errors. If your Hibernate jar is in jre/lib/ext, then, it's likely you will have to put the MySQL jar there. The Hibernate jar really belongs with your webapp, not in any more global location. I agree completely with your judgments expressed here, but that approach seems not to work, in my case. Why? - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
From: Bob Marcum [mailto:bmar...@bcscomputers.com] Subject: Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver I did a find scan of my system, looking for other copies of both hibernate3.jar and mysql-connector-java-3.1.10-bin.jar to confirm there are no other copies which could be in classpath. Your find might have been a bit too specific, since you mustn't have any jars for any version of Hibernate or MySQL in your webapp's classloader branch, other than in WEB-INF/lib. There is a link to the mysql driver jar in hibernate-3.0's own lib directory. What do you mean by hibernate-3.0's own lib directory? Is this a link somehow inside the Hibernate jar? Are the Hibernate classes somewhere else besides the jar in WEB-INF/lib? When I re-run the application, I am right back where I was. I get java.lang.ClassNotFoundException: com.mysql.jdbc.Driver. What's in the Context element for your webapp? Since you're using C3P0 pooling, you should not have a Resource element inside the Context, otherwise Tomcat will also attempt to do pooling for the driver. My webapp cannot see the mysql driver jar, although it clearly sees the hibernate jar. Post the complete stack trace for the CNFE. Still sounds like you've got another copy or version of the MySQL jar around, causing classloader conflicts. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Bob Marcum wrote: Suggestions, gents? Showing us the full stack trace would help. Mark - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Thank you all for your help. Caldarale, Charles R wrote: From: Bob Marcum [mailto:bmar...@bcscomputers.com] Subject: Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver I did a find scan of my system, looking for other copies of both hibernate3.jar and mysql-connector-java-3.1.10-bin.jar to confirm there are no other copies which could be in classpath. Your find might have been a bit too specific, since you mustn't have any jars for any version of Hibernate or MySQL in your webapp's classloader branch, other than in WEB-INF/lib. I did a find on mysql-connector-java-*.jar. Should have caught everything. There is a link to the mysql driver jar in hibernate-3.0's own lib directory. What do you mean by hibernate-3.0's own lib directory? Is this a link somehow inside the Hibernate jar? Are the Hibernate classes somewhere else besides the jar in WEB-INF/lib? No. I am afraid I have confused the issue. There is a lib directory in the hibernate distribution. One is instructed by the dist readme to copy your jdbc driver into that lib ... but it is only used when running the tests to confiem hibernate works okay. I have explored this a little more since my last post. When I re-run the application, I am right back where I was. I get java.lang.ClassNotFoundException: com.mysql.jdbc.Driver. What's in the Context element for your webapp? Since you're using C3P0 pooling, you should not have a Resource element inside the Context, otherwise Tomcat will also attempt to do pooling for the driver. I am using a context.xml which has the following in it: Context debug=5 Resource name=jdbc/CSRapp description=DB Connection type=javax.sql.DataSource scope=shareable driverClassName=com.mysql.jdbc.Driver factory=org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory url=jdbc:mysql://localhost:3306/CSRapp username=CSRapp password=CSRapp auth=Container validationQuery=select 1 maxActive=10 maxWait=5000 maxIdle=4 / /Context This is as recommended by tomcat documentation, as I understand that documentation. My webapp cannot see the mysql driver jar, although it clearly sees the hibernate jar. Post the complete stack trace for the CNFE. Here is the complete stack trace from catalina.log. I have the debugger set to spit out a lot of data: serviceProviderRecord = [Ljava.lang.String;@13c6a22 16:38:33,723 INFO Environment:464 - Hibernate 3.0.5 16:38:33,734 INFO Environment:477 - hibernate.properties not found 16:38:33,741 INFO Environment:510 - using CGLIB reflection optimizer 16:38:33,753 INFO Environment:540 - using JDK 1.4 java.sql.Timestamp handling 16:38:34,321 INFO Configuration:1110 - configuring from resource: /hibernate.cfg.xml 16:38:34,323 INFO Configuration:1081 - Configuration resource: /hibernate.cfg.xml 16:38:34,658 INFO Configuration:444 - Mapping resource: org/bcs/server/utils/ServiceProvider.hbm.xml 16:38:35,018 INFO HbmBinder:260 - Mapping class: org.bcs.server.utils.ServiceProvider - ServiceProvider 16:38:35,133 WARN HbmBinder:422 - Could not perform validation checks for component as the class org.bcs.server.utils.ServiceProvider was not found 16:38:35,145 INFO Configuration:1222 - Configured SessionFactory: null 16:38:35,149 INFO Configuration:875 - processing extends queue 16:38:35,153 INFO Configuration:879 - processing collection mappings 16:38:35,155 INFO Configuration:888 - processing association property references 16:38:35,156 INFO Configuration:917 - processing foreign key constraints 16:38:36,141 INFO NamingHelper:26 - JNDI InitialContext properties:{} 16:38:36,147 INFO DatasourceConnectionProvider:51 - Using datasource: java:comp/env/jdbc/CSRapp 16:38:36,166 WARN SettingsFactory:103 - Could not obtain connection metadata org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver' at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1136) at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880) at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:59) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:72) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1463) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1004) at org.bcs.server.db.HibernateUtil.clinit(Unknown Source) at org.bcs.server.db.ModelFacade.findAllLikeThis(Unknown Source) at org.bcs.server.SelectionSearchServiceImpl.findAllLikeThis(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25
Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Context debug=5 Resource name=jdbc/CSRapp description=DB Connection type=javax.sql.DataSource scope=shareable driverClassName=com.mysql.jdbc.Driver factory=org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory url=jdbc:mysql://localhost:3306/CSRapp username=CSRapp password=CSRapp auth=Container validationQuery=select 1 maxActive=10maxWait=5000 maxIdle=4 / /Context This configuration is using a tomcat managed database pool. Put your mysql jar file in tomcat's lib folder and you'll see the error go away. --David Bob Marcum wrote: Thank you all for your help. Caldarale, Charles R wrote: From: Bob Marcum [mailto:bmar...@bcscomputers.com] Subject: Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver I did a find scan of my system, looking for other copies of both hibernate3.jar and mysql-connector-java-3.1.10-bin.jar to confirm there are no other copies which could be in classpath. Your find might have been a bit too specific, since you mustn't have any jars for any version of Hibernate or MySQL in your webapp's classloader branch, other than in WEB-INF/lib. I did a find on mysql-connector-java-*.jar. Should have caught everything. There is a link to the mysql driver jar in hibernate-3.0's own lib directory. What do you mean by hibernate-3.0's own lib directory? Is this a link somehow inside the Hibernate jar? Are the Hibernate classes somewhere else besides the jar in WEB-INF/lib? No. I am afraid I have confused the issue. There is a lib directory in the hibernate distribution. One is instructed by the dist readme to copy your jdbc driver into that lib ... but it is only used when running the tests to confiem hibernate works okay. I have explored this a little more since my last post. When I re-run the application, I am right back where I was. I get java.lang.ClassNotFoundException: com.mysql.jdbc.Driver. What's in the Context element for your webapp? Since you're using C3P0 pooling, you should not have a Resource element inside the Context, otherwise Tomcat will also attempt to do pooling for the driver. I am using a context.xml which has the following in it: Context debug=5 Resource name=jdbc/CSRapp description=DB Connection type=javax.sql.DataSource scope=shareable driverClassName=com.mysql.jdbc.Driver factory=org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory url=jdbc:mysql://localhost:3306/CSRapp username=CSRapp password=CSRapp auth=Container validationQuery=select 1 maxActive=10maxWait=5000 maxIdle=4 / /Context This is as recommended by tomcat documentation, as I understand that documentation. My webapp cannot see the mysql driver jar, although it clearly sees the hibernate jar. Post the complete stack trace for the CNFE. Here is the complete stack trace from catalina.log. I have the debugger set to spit out a lot of data: serviceProviderRecord = [Ljava.lang.String;@13c6a22 16:38:33,723 INFO Environment:464 - Hibernate 3.0.5 16:38:33,734 INFO Environment:477 - hibernate.properties not found 16:38:33,741 INFO Environment:510 - using CGLIB reflection optimizer 16:38:33,753 INFO Environment:540 - using JDK 1.4 java.sql.Timestamp handling 16:38:34,321 INFO Configuration:1110 - configuring from resource: /hibernate.cfg.xml 16:38:34,323 INFO Configuration:1081 - Configuration resource: /hibernate.cfg.xml 16:38:34,658 INFO Configuration:444 - Mapping resource: org/bcs/server/utils/ServiceProvider.hbm.xml 16:38:35,018 INFO HbmBinder:260 - Mapping class: org.bcs.server.utils.ServiceProvider - ServiceProvider 16:38:35,133 WARN HbmBinder:422 - Could not perform validation checks for component as the class org.bcs.server.utils.ServiceProvider was not found 16:38:35,145 INFO Configuration:1222 - Configured SessionFactory: null 16:38:35,149 INFO Configuration:875 - processing extends queue 16:38:35,153 INFO Configuration:879 - processing collection mappings 16:38:35,155 INFO Configuration:888 - processing association property references 16:38:35,156 INFO Configuration:917 - processing foreign key constraints 16:38:36,141 INFO NamingHelper:26 - JNDI InitialContext properties:{} 16:38:36,147 INFO DatasourceConnectionProvider:51 - Using datasource: java:comp/env/jdbc/CSRapp 16:38:36,166 WARN SettingsFactory:103 - Could not obtain connection metadata org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver' at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1136) at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880) at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:59) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:72
Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Caldarale, Charles R wrote: From: David Smith [mailto:d...@cornell.edu] Subject: Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver This configuration is using a tomcat managed database pool. Put your mysql jar file in tomcat's lib folder and you'll see the error go away. But the stated intent is to use C3P0 pooling, rather than Tomcat's pooling; in that case, the Resource element must be removed and instead configured via whatever mechanism C3P0 wants. Can't have both. - Chuck No argument here. I'm just diagnosing the current issue. If the OP wants help with C3PO, that should be the configuration we are given. --David - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
--- On Mon, 7/20/09, David Smith d...@cornell.edu wrote: From: David Smith d...@cornell.edu Subject: Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver To: Tomcat Users List users@tomcat.apache.org Date: Monday, July 20, 2009, 6:16 PM Caldarale, Charles R wrote: From: David Smith [mailto:d...@cornell.edu] Subject: Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver This configuration is using a tomcat managed database pool. Put your mysql jar file in tomcat's lib folder and you'll see the error go away. But the stated intent is to use C3P0 pooling, rather than Tomcat's pooling; in that case, the Resource element must be removed and instead configured via whatever mechanism C3P0 wants. Can't have both. - Chuck No argument here. I'm just diagnosing the current issue. If the OP wants help with C3PO, that should be the configuration we are given. --David Late to the thread, and this is probably overkill. This is my understanding concerning how the Tomcat / Hibernate / database environment works. Your mileage may vary, and I will probably be corrected by some people on the list. Please note that I've only used Tomcat managed database pooling. Tomcat Managed Database Pooling === Anyway, here is my environment. OS - Fedora 10 === jdk/jre - 1.6.0_14 Tomcat - 6.0.20 MySQL - 5.0.77-1 IDE - NetBeans 6.7 Hibernate - 3.2.5.ga (provided with NetBeans) OS - Windows/XP Professional SP 3 === jdk/jre - 1.6.0_14 Tomcat - 6.0.20 MySQL - 5.1.31 IDE - NetBeans 6.7 Hibernate - 3.2.5.ga (provided with NetBeans) I've chosen to use Tomcat's database pooling for the NetBeans DVD Store tutorial sample application. This necessitates several changes in how the application is configured. Basics == 1. Per Tomcat documentation, I've placed mysql-connector-java-5.0.8-bin.jar in Tomcat's lib directory. This makes it available to Tomcat in order to set up database pooling 2. All Hibernate jars are located in WEB-INF/lib. NetBeans builds the war file correctly, so I don't have to copy any jar files around. Web Application === This also follows the Tomcat documentation for creating Tomcat-managed connection pooling. 1. In META-INF/context.xml: ?xml version=1.0 encoding=UTF-8? Context antiJARLocking=true path=/DVDStore Resource auth=Container driverClassName=com.mysql.jdbc.Driver maxActive=30 maxIdle=10 maxWait=1 name=jdbc/sakila password=* type=javax.sql.DataSource url=jdbc:mysql://localhost/sakila username=*/ /Context Obviously, replace the asterisks with the appropriate username and password. Replace the database url with your appropriate database. 2. In WEB-INF/web.xml: resource-ref descriptionThis is a MySQL database connection/description res-ref-namejdbc/sakila/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref Hibernate Configuration === So far, this has all been more or less boilerplate Tomcat configuration. The next step is to get Hibernate to talk to Tomcat's database connection pool as opposed to its own connection pool or a direct connection. After searching a bit on the Internet, I found that the following connection information works. 1. In hibernate.cfg.xml located in WEB-INF/: !-- using container-managed JNDI -- propertyname=hibernate.connection.datasource java:comp/env/jdbc/sakila /property Note that jdbc/sakila matches the web.xml resource-ref-name, which matches the name attribute in context.xml. java:comp/env/ is the namespace to look up the jdbc reference. No other connection or pooling information should be present in your hibernate.cfg.xml file. Application Code Since Hibernate hides a lot of the details for connection management, this code should not have to change. In particular: 1. Creating the SessionFactory // SessionFactory from standard hibernate.cfg.xml file try { sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory(); } catch (Throwable ex) { // Log the exception. log.fatal(Initial SessionFactory creation failed., ex); throw new ExceptionInInitializerError(ex); } 2. Getting the SessionFactory public static SessionFactory getSessionFactory() { return sessionFactory; } For my application, both of these code snippets live in HibernateUtil.java. My code also creates an mbean for monitoring Hibernate. You can then wrap this code up in a servlet context listener, which should then create the session factory (which connects to the Tomcat - provided connection pool) at application startup. It's also handy for cleaning up resources when the application
RE: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
From: its_toas...@yahoo.com [mailto:its_toas...@yahoo.com] Subject: Re: Seeking the right solution to java.lang.ClassNotFoundException: com.mysql.jdbc.Driver PS - I just hacked together the Hibernate-controlled database connection / pooling on a freshly installed Tomcat 6.0.20. It works as advertised. A very comprehensive and useful writeup; thanks. Please consider adding the Hibernate-controlled pooling description to the Tomcat FAQ/Wiki Database section - or at least a pointer to the relevant Hibernate doc. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org