1

i can connect mysql with java using eclipse in a java application with these statements

String unicode = "?useUnicode=yes&characterEncoding=UTF-8";
Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/ams-competation" + unicode,
                    username, password);

and it works good

but my problem is when i tried to connect to mysql with a server application i got this exception

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver what am i doing wrong?thank you all

Edit

i have added mysql-connector already

7
  • Please include the driver jar file in either server or application lib. Commented Jun 22, 2012 at 10:02
  • @Santosh i added it already but forgot to tell you, sorry Commented Jun 22, 2012 at 10:04
  • @tottiroma: If you have added it, you hadn't got this error message Commented Jun 22, 2012 at 10:07
  • @buc really i added it , and i can see it on the Referenced Libraries tab on Eclipse Commented Jun 22, 2012 at 10:08
  • Yes you have added it in Eclipse, but you have not added it to the application server. Commented Jun 22, 2012 at 10:09

6 Answers 6

3

I think you have not included mysql drive jar in your web project.

put mysql-connector-java.. jar file in your web projects lib folder

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

6 Comments

Goto your WEB-IF/lib folder and check if jar is there or not?
can i copy past the jar to that folder?
You can also put it directly in your servers lib folder... what web server you are using?
Yes you can you can copy jar to lib folder directly
tomkat , i am trying but it take some minutes cos the client is android
|
1

for that you need to add the mysql-connector jar in the classpath.

This is because eclipse is not able to find the jar file you specified.

Hence put the jar file in the server`s lib directory

another way is to put jar file it in /WEB-INF/lib eclipse itself will notice it and get it.

3 Comments

it should be added to the server`s lib folder by doing so you can resolve the exception..
can i add it to that folder using copy past , or i have to do some configuration steps ?
i really thank you for helping , hope i could accept more than one answer :( , really very thank you for helping , it works
1

Did you add the MySQL driver to the server?

It depends on the application server where the jar file is needed to be added:

  • Apache Tomcat: $CATALINA_HOME/common/lib
  • GlassFish server: GLASS_FISH_INSTALL_DIR\lib

Or add it the WEB-INF/lib folder of your web application

Try adding the mysql-connector-java-5.1.20-bin.jar file (downloadable from: http://dev.mysql.com/downloads/connector/j/ ), and restart the server.

5 Comments

did you add it to the correct location AND restart the server afterwards?
i add it on this way , right click on the project , buid path, configuration build path , add external jar file , then select mysql-connector-java-5.1.13 i can see the jar file on references libraries tab , but not on WEB-INF
If you just reference it to your project it will NOT be uploaded to the server. You need to add it to the correct folder too.
and how can i do that ? and what is the correct folder , thank you
It is in my answer... It depends on your server. If you don't want to use it from multiple applications then you can also put it in the WEB-INF/lib folder of your web application
0

Add the Connector/J jar file to the server's classpath (or lib folder)

Comments

0

add my sql connection jar file to your project. Its name will be something like "mysql-connector-java-5.1.13-bin.jar"

Comments

0

connect connector/J 8.0.11 with eclipse oxygen by following line of code.

 Class.forName("com.mysql.cj.jdbc.Driver");
           conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/testing?autoReconnect=true&useSSL=false", "AF", "birru123");

        Statement st = conn.createStatement();

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.