Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

This question already has an answer here:

I am a newbie to J2EE.I have checked similar questions but nothing helped.

I am creating a simple login application but i am facing the above error.

I have mysqlconnector in build path and a lib folder as shown in the image :SQL connector

The source code of the application is as follows:

LoginDao.java This file connects the application to mysql database.

String userName = "root";
String password = "mysql";

I have provided the username and password of mysql here.Is this correct?

For this I have created a database in mysql:

create database form;
use form;


create table login(username varchar(20),pass varchar(20));
show tables;
insert into login values("nehal",12345);

Now the project runs properly but when i enter username as nehal and password:12345, it gives the above error:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
share|improve this question

marked as duplicate by Mark Rotteveel java Jun 11 '16 at 7:24

This question was marked as an exact duplicate of an existing question.

    
It seams you did not set the path of your connection jar file . – Mehraj Malik Jun 10 '16 at 10:35
    
Can you give it a try : Class.forName(driver).newInstance();. To establish Db connection password and username should be your DB credential. – Helios Jun 10 '16 at 10:38
    
You should edit out please do not downvote the question. That tends to attract downvotes and one reason for downvotes is when people add things (like this statement) that aren't relevant to the question. – Lexi Jun 10 '16 at 11:51
    
Why is "ClassNotFoundException" even remotely confusing? You don't have the class in the CLASSPATH, hence you don't have the jar that contains it in the CLASSPATH, hence fix your CLASSPATH. – Neil Stockton Jun 10 '16 at 15:37
    
@NeilStockton I am a newbie😐😐... How? – nrb Jun 10 '16 at 15:45

1 way =>Paste the mysqlconnector.jar file in jre/lib/ext folder.

2 way => set classpath

open comman prompt and write:- C:>set classpath=c:\folder\mysql-connector-java-5.0.8-bin.jar;.;

in IDE : Right Click the

project -- > build path -- > configure build path

In Libraries Tab press Add External Jar and Select your jar.

share|improve this answer
    
if i am using IDE, why should i do that? – nrb Jun 10 '16 at 10:41
    
which IDE are you using? – Mehraj Malik Jun 10 '16 at 10:44
    
Eclipse (check the link SQL connector above in the question) – nrb Jun 10 '16 at 10:44
    
Bro,Read the content properly i have done that – nrb Jun 10 '16 at 10:47
    
java67.blogspot.com/2015/07/… I hope this will help – Mehraj Malik Jun 10 '16 at 10:54

Don't know eclipse that much but i would guess that your library is mussing at runtime. As i see you use apache tomcat and it seems that it doesn't has that mysql jar.

You have to add that jar to your apache tomcat. See Where do I have to place the JDBC driver for Tomcat's connection pool?

share|improve this answer
    
Still it gives the same error!! – nrb Jun 10 '16 at 10:54
    
You also have to register that driver in apache tomcat. Example from tomcat.apache.org/tomcat-8.0-doc/… DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); conn = DriverManager.getConnection("jdbc:oracle:oci8:@database","us‌​ername","password"); – Hillkorn Jun 10 '16 at 12:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.