I\'ve seen several similar questions on stackoverflow, but they didn\'t solved my problem. This one is specially useful, since it points to official tomcat documentation an
The solutions provided there is, in short: tomcat needs jdbc database drivers to be copied to
$CATALINA_HOME/lib/
, because it will not find them underWEB-INF/lib/
. Ok, but it still does not work for me, and I am becoming mad.
This depends on how you load the driver.
If you configure the driver within you tomcat and provide it to the application then this statement is correct.
But you load the driver directly within your application. Then both ways, $CATALINA_HOME/lib/
(in tomcat) as well as WEB-INF/lib/
(in application) should work.
But Spring use a special way to load that class Class.forName(driverClassNameToUse, true, ClassUtils.getDefaultClassLoader())
and I dont know how it behave for files in $CATALINA_HOME/lib/
so I would try to put the files in your application WEB-INF/lib/
folder
Solved!
Arturs Licis' suggestion was the key. Somehow the mysql driver had been incorrectly downloaded. It seemed a .jar file, but failed to load. Tomcat was showing just the first level of the exception:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
[...]
But when I coded a very simple helloworld with Class.forName("com.mysql.jdbc.Driver"), the following error was shown instead:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
[...]
Caused by: java.util.zip.ZipException: invalid LOC header (bad signature)
[...]
Eureka! Opening the .jar file on WinRar shows that it can be open... but with some errors.
Downloading the driver again did solve the problem.
Downvote for myself :-(