• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

error " java.sql.SQLException: Cannot create JDBC driver of class 'com.mysql.jdbc.Dr

 
Ranch Hand
Posts: 333
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I'm currently taking a class to learn java but I'm at a point I don't know if I can move forward. I'm receiving an error "java.sql.SQLException: Cannot create JDBC driver of class 'com.mysql.jdbc.Driver' for connect URL 'jdbc://localhost:3306?autoReconnect=true' "

I tried Googling and found a few of the same questions at StackOverflow but the suggestions do not help me.

I'm using MySQL 5.7.13, Workbench is 6.3 and MySQL
mysql-connector-java-5.1.39-bin.jar is in both my WEB-INF folder and now ( as suggested on a StackOverflow ) in my Tomcat lib folder
Tomcat is under C:\tomcat-8.0
context.xml is under META-INF

My LocalMySQLCP class file has some unused variables on it currently. As part of our lesson we refactored a class file from trying to connect one way ( where the user name, password, database URL etc is on the class ) to trying to connect using information in the context.xml. My instructor said it looks like my servlet is trying to connect via. the old way and perhaps I may have left some code on my LocalMySQLCP class file but I can't see anything.

It does seem to connect as a browser comes up but then the error is shown on the console.

I don't see anything here that would use the old way of connecting. Any suggestions please?

My context.xml



My Servlet





 
Lisa Austin
Ranch Hand
Posts: 333
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also I forgot my ConnectionPool class


 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where did you put the jar file containing the driver class?
 
Lisa Austin
Ranch Hand
Posts: 333
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Where did you put the jar file containing the driver class?



Hey Bear,
It's under my WEB-INF lib folder. I made some changes and I think it seems to be working except for a warning about SSL connection but I think I can ignore a Warning ( right? )

Thank You so much for trying to help. I was getting pretty frustrated here.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad it's working.
 
Bartender
Posts: 1845
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm pretty sure that for Tomcat connection pooling, the driver needs to be in the [TOMCAT]/lib directory (ref: https://tomcat.apache.org/tomcat-8.0-doc/jndi-datasource-examples-howto.html)

My other suggestion would be to clean up those unused variables and methods that you no longer need in the LocalMySQLCP class
 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stefan Evans wrote:I'm pretty sure that for Tomcat connection pooling, the driver needs to be in the [TOMCAT]/lib directory (ref: https://tomcat.apache.org/tomcat-8.0-doc/jndi-datasource-examples-howto.html)

My other suggestion would be to clean up those unused variables and methods that you no longer need in the LocalMySQLCP class



Correct. Connection pools are created by Tomcat and owned by Tomcat. They are not part of the web application and in fact, one pool can be shared by multiple applications. So the driver used by the pool must be located in TOMCAT_HOME/lib.

You can take it as a general rule that any classes or jars referenced in the Tomcat server.xml or context.xml files must be located in TOMCAT_HOME/lib. That's because the server.xml and context xml files are digested by Tomcat itself and the core Tomcat classpath does not include any of the webapp classpaths. so their WEB-INF/classes and WEB-INF/lib directories would be inaccessible to the primary Tomcat processes.
 
They gave me pumpkin ice cream. It was not pumpkin pie ice cream. Wiping my tongue on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic