0

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
nrb
  • 5
  • 8
  • 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
  • how can anyone tell you that until you tell them how you are running whatever you are running? build path (for compiling) != runtime CLASSPATH – Neil Stockton Jun 10 '16 at 16:03

2 Answers2

1

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.

Mehraj Malik
  • 14,872
  • 15
  • 58
  • 85
0

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?

Community
  • 1
  • 1
Hillkorn
  • 633
  • 4
  • 12
  • 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 https://tomcat.apache.org/tomcat-8.0-doc/jndi-datasource-examples-howto.html DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); conn = DriverManager.getConnection("jdbc:oracle:oci8:@database","username","password"); – Hillkorn Jun 10 '16 at 12:50