1

I try to connect to MySQL database (works perfect when I connect to it without servlet) and get the below error all the time:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

This error means (as I understand) that I don't have some jar files in my project. but this is not true, because I have those Jars. !Moreover, if I realy didn't had those jar, I could not have connected to the database anyway.

What I missed?

1
  • If you're running tomcat you can probably drop it into the lib directory? Commented Apr 24, 2015 at 13:07

2 Answers 2

2

By looking at those tags this is a web application. So the error clearly states you don't have your SQL Venders Driver jars in the class path.

You can put this jar in your Project/WEB-INF/lib folder and restart whatever web server you are using. Then you will be good to go.

Sign up to request clarification or add additional context in comments.

Comments

1

Your mysql jdbc jar driver isn't in your classpath.

If you run it from a servlet, it uses the classpath of your servlet container. This classpath probably contains it.

Find mysql-connector-java where you can, and copy into your classpath.

6 Comments

sorry for my lack of knowledge, but i'm not sure how to do it. i saw here a guide that say only to copy it to the src folder. is it correct? anyway-his way doesn't fix the problem.
@dennisbergkamp You are on a large q&a site, formulate your question and ask it. It is absolutely not a problem here, if you ask a lot.
can u explain please how to add the jar to classpath? i don't find an answer for that, and also posted it and didn't answered yet. thanks
@dennisbergkamp Yes, but it is already a different question. Ask this as a new one, with proper spelling (forget "u", etc), and give the exact details of the technologies you are using.
working!! thanks all of u (i putted the jar where jafar ali told me)
|

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.