This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Help - - - ClassNotFoundException: com.mysql.jdbc.Driver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Help - - - ClassNotFoundException: com.mysql.jdbc.Driver" Watch "Help - - - ClassNotFoundException: com.mysql.jdbc.Driver" New topic
Author

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

Michael Cropper
Ranch Hand

Joined: Sep 30, 2009
Posts: 137
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

Joined: Jul 20, 2005
Posts: 9961
    
163

Have you placed the MySQL JDBC driver jar file in the classpath of your application?


[My Blog] [JavaRanch Journal]
Michael Cropper
Ranch Hand

Joined: Sep 30, 2009
Posts: 137
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

Joined: Jul 20, 2005
Posts: 9961
    
163

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

Joined: Sep 30, 2009
Posts: 137
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

Joined: Jul 20, 2005
Posts: 9961
    
163

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

Joined: Sep 30, 2009
Posts: 137
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help - - - ClassNotFoundException: com.mysql.jdbc.Driver
 
Similar Threads
Netbeans error JSP and MySQL
is exist any multi record catalogue? or better to use DB? or array?
classpath
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
classNotFoundException for Driver