1

I'm developing a web application in java where I'm trying to connect to a MySQL database using JDBC template ( with springs dao) but I always get:

SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/DealingOfInsiders] threw exception [Request processing failed; 
nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver '] with root cause
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
 [....]

I think the problem is coming from the file mysql-connector-java-5.1.25-bin.jar which contains the targeted class ... So I tried many things to get this problem solve :

  • I've configured the build path of my project whith this jar but it didn't worked

  • I ve also put the file in the folder : WEB-INF/lib , didn't worked

  • I ve configured a classpath variable to this jar in eclipse ( preference ->java->buildpath->classpath variabe ) it didn't worked

  • I have put the jar file in the tomcat library but it didn't work as well

3 Answers 3

1
 'com.mysql.jdbc.Driver '
                       ^^ // remove this space
Sign up to request clarification or add additional context in comments.

3 Comments

yeah thanks ! it seems that this space was the problem (erf) but now i get another one: java.lang.ClassNotFoundException: org.springframework.dao.DuplicateKeyException maybe you have clues ^^
Do you have all the Spring JARS in your web app library ? Also check if the query is correct.
i 'd like to but i can't post the entire stack too long in comments and as i m new here i cannot answer my topic before 6 hours , i'll try to check on the internet and if i don't find anything i ll come back here ^^ thx again ps : i have every jars in my web app lib and I'm currently checking the query
0

There appears to be a trailing space on the name?

'com.mysql.jdbc.Driver '

Apart from that, "com.mysql.jdbc.Driver" is correct.

The WEB-INF/lib folder is a good place for project-specific drivers & libraries; keeping the Tomcat shared folders up-to-date is not so easy.

Back in JDBC days you had to load the class with Class.forName( clazzName) to register it before you asked JDBC for a connection, but that's not the issue here.

2 Comments

Ask that, with details, in a separate question plz. Care to give me (or the other guy, or both of us) an upvote first?
i need 15 ofreputation to do it sorry :S
0

I had this issue but with the Postgres driver and I'm using Eclipse. If you're using Tomcat 7, try adding the JAR file to the lib folder in your Tomcat directory. That worked for me. I didn't have to use Class.forName() or put the JAR in my classpath. I hope this helps you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.