Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help - - - ClassNotFoundException: com.mysql.jdbc.Driver

 
Michael Cropper
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I have been trying to connect/create a DB through .java files but keep coming up with the problem, ClassNotFoundException: com.mysql.jdbc.Driver.

I am trying to connect to a MySql DB with JDBC, but guessing from the error it is not installed correctly?

Not really sure where to look for help as i've been searching for hours now and nothing useful is coming up anywhere on google.

I can connect to MySql through the command line, create db's, insert etc so that is all good.

Any ideas on what I can try next?

Thanks
CKS
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you placed the MySQL JDBC driver jar file in the classpath of your application?
 
Michael Cropper
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think so.....

I have a folder 'OtherTuts' then within this there is MysqlConnect.java and .class (it compiled ok - Code below) and the 'mysql-connector-java-5.1.10-bin.jar' file which I think is the JDBC driver? Is that correct?

Code for MysqlConnect.java (got it from a tutorial)
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Cropper wrote:the 'mysql-connector-java-5.1.10-bin.jar' file which I think is the JDBC driver? Is that correct?

That's correct. You will have to make it available as part of the classpath. See this FAQ on how to set the classpath
 
Michael Cropper
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers got that bit working now (got another problem now though:-S ). I had already got the file in the classpath but I noticed on the link you posted about Java automatically checking the ext folder in the jre file so I put a copy there too and that seemed to work.

Now the problem that it is getting stuck on now is... 'com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure' which is being caused by the following line of code in MysqlConnect.java.... 'conn = DriverManager.getConnection(url+dbName,userName,password);'

Any ideas on that one?

I have just tried to connect to mysql via the command line again and it wont connect, getting the following error after typing, 'mysql -u root'

'error 2003 <HY000>: can't connect to MySql server on 'localhost' <10061>'

It did this previously and I had to restart my computer to get this working again. Why does this happen though?

Going to try a quick restart now to give the java file another try.

Cheers for all the help it is much appreciated I have been getting more and more confused with every outdated and inaccurate tutorial I have been reading.

CKS
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Cropper wrote:
Now the problem that it is getting stuck on now is... 'com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure' which is being caused by the following line of code in MysqlConnect.java.... 'conn = DriverManager.getConnection(url+dbName,userName,password);'

Any ideas on that one?



See if some of the discussion here helps
 
Michael Cropper
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just done a restart and that seems to have solved the problem. Odd.

Getting this problem now.... java.sql.sqlexception: access denied for user'root'@'localhost'

How do I check the usernames and passwords that are available to use?

EDIT: Just had a good google around and the best piece of info I could find was to re-install so done that. All working now. Thank god!!

Time to start playing around now and start developing :-D Thanks for all the help, im sure ill be back once my Java code isn't doing quite what it should be he he.

CKS
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic