Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception caught java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

 
Rod Hittle
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I gave up on ACCESS and the latest version of JAVA. I'm still stuck.
So in installed MySQL. Made a schema and a table and filled it with some data. I was able to run queries against that schema/table.
The schema is visualcafe and the one table is customer.


I installed the java JAR file here (or better it installed itself there):
C:\Program Files (x86)\MySQL\MySQL Connector J\ mysql-connector-java-5.1.36-bin.jar

I went to CONTROL PANEL and they SYSTEM and then ADVANCED SYSTEM SETTINGS. In the 'Systems Properties' window I chose ADVANCED tab.
And then button ENVIRONMENTAL VARIABLES. I chose NEW and in window 'NEW USER VARIABLE" I put in ...
Variable name: MySQL
Variable value: .;C:\Program Files (x86)\MySQL\MySQL Connector J\ mysql-connector-java-5.1.36-bin.jar
I thought that odd but to add the .; but that is JAVA ALL-IN-ONE FOR DUMMIES instructed on page 731


Here is the JAVA Class




But when I run it I still get Exception caught java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
I made sure the user id and password used in the JAVA match what I made when I installed the MySQL

I am truly deeply stumped.





 
Paul Clapham
Sheriff
Posts: 21567
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no idea why your book told you to create that environment variable. Perhaps it's used by something else which the book describes. But what is actually needed at this point is to put that jar file into the classpath which is used when you run that application. By this time the book ought to have told you how to configure the classpath in that way... in fact, if you're already at page 731 it should have done that a long time ago.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rod Hittle wrote:I am truly deeply stumped.

The error message you get is pretty straightforward: the Java runtime can't find the com.mysql.jdbc.Driver class when you run the DataBaseDemo application. That's the very first step: if it can't find the driver, there's no way you can connect to the database and does credentials are useless as well :)

Which command do you invoke to execute the DataBaseDemo application?
 
Rod Hittle
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs, I agree that it is pretty straightforward. So why can’t it find the driver?
Paul Chapman, I though creating the environment variable (and putting the directory path in it) the process of putting the jar file in the ClassPath.
From the book “Java ALL-IN-ONE FOR DUMMIES” 3RD EDITION by Doug Lowe copyright 2011
Pg 771

2. Add the driver’s jar file to your ClassPath variable.
To change the ClassPath, open Control Panel and double-click System.
Then click the Advanced tab, and then click Environment Variables. You then click New to add a new environment variable. The ClassPath veriable has to specify the complete path for the connector’s jar file. Fpr example. Here’s a sample ClassPath variable for a driver located in c:\mysql:
.;c:\Program Files (x86)\MySQL\MySQL Connector J\ mysql-connector-java-5.1.36-bin.jar

Notice the ClassPath variable starts with a period and a semicolon. This ensures that Java can find classes that are in the current directory


I am using Eclipse to runt the class.
I am on Windows 7 Pro 64 bit.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rod Hittle wrote:Roel De Nijs, I agree that it is pretty straightforward. So why can’t it find the driver?

Probably because the driver jar is not on the classpath of the program.

Can you see in Eclipse the driver jar (mysql-connector-java-5.1.36-bin.jar ) under Referenced Libraries? If not, that's the root cause of your problem. Here you'll find how you can add an (external) JAR file to your project using Eclipse.

Good luck!
 
Tim Holloway
Saloon Keeper
Posts: 18363
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Couple of things to note:

1. Package names beginning with upper-case letters violate Java conventions. It's legal, but some Java tools may not function properly.

2. Make sure that you're not getting zapped by the spaces in the path name. If you type a command line like so:


It's going to bite you, because the space between "MySQL" and "Connector" and "J" will cause the command-line parser to incorrectly interpret the classpath. You need quotes around the pathname.

I may be simply pointing out things you already know, but I've learned that a lot of times other people don't know things that we've learned to take for granted.
 
Rod Hittle
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel,
you provided a clue. It is the fact I am using Eclipse.
All the sites I found on Google just are too cryptic but did give enough clues to lead me to a solution. I made a doc that think will be helpful to all 'greenhorns'. I will attempt to attach it. I hope it will be available to others stuck such as myself.
 
Paul Clapham
Sheriff
Posts: 21567
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rod Hittle wrote:Paul Chapman, I though creating the environment variable (and putting the directory path in it) the process of putting the jar file in the ClassPath.


I'm not "Chapman". (Attention to detail is important for programmers.)

And creating the right environment variable would set the classpath for you. But you chose the wrong name ("MySQL") for an environment variable which is supposed to represent the classpath. Did the book tell you to use that name?

But now you tell us that you're using Eclipse. Eclipse doesn't use that environment variable. Did the book tell you to use Eclipse? I'm assuming it didn't, otherwise it would have told you how to set the build path for an Eclipse project instead of how to set an environment variable for the classpath.
 
Rod Hittle
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul, this is what happens when I use Post Reply as opposed to Quick Reply.
That said Paul Clapham...
No the book did not say anything about WHAT to name the variable. I don't know what is wrong with "MySQL". For all I know I could have named it "George". And there is no clue given between the variable name and how that name might be referenced in the Java code. Either from the book or any hits I got from google search.
I am guessing that in Class.forName("com.mysql.jdbc.Driver");
that maybe the name of the environmental variable MUST be "mysql" as opposed to any name I might make up.
 
Rod Hittle
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will try an attachment again.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rod Hittle wrote:Paul, this is what happens when I use Post Reply as opposed to Quick Reply.

Huh? How can that make a difference in your typing?
 
Rod Hittle
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because when I use the POST REPLY the whole screen is just for that, you can't see the rest of the previous post. Hence you have to clearly remember what you saw. With quick reply you only need to scroll up to see the content of previous post. I don't have to depend on my poor memory.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rod Hittle wrote:because when I use the POST REPLY the whole screen is just for that, you can't see the rest of the previous post. Hence you have to clearly remember what you saw.

I assume you are using the website on a mobile device, because on a desktop I see the previous posts at the bottom of the screen (under preview/submit buttons). If I need to address someone and don't want to rely on my volatile memory, I copy and paste the name.
 
Rod Hittle
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, a desk top. and just the one previous post, Silly me, I never bothered to scroll DOWN.

Change of subject. Any reason that I can't see any attachment that I have attached in a previous post.
There is not that many things to do wrong to make it not actually show up.
 
Paul Clapham
Sheriff
Posts: 21567
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rod Hittle wrote:No the book did not say anything about WHAT to name the variable. I don't know what is wrong with "MySQL". For all I know I could have named it "George". And there is no clue given between the variable name and how that name might be referenced in the Java code. Either from the book or any hits I got from google search.


Well, it sure looks like the book is trying to tell you how to set your classpath, which is what you're needing to do here. I believe the correct name for the environment variable is "classpath" but I can't remember for sure since using an environment variable isn't a good way to set your classpath and I haven't done it that way for years.

I find it hard to believe that the book doesn't tell you what name to provide, but since you said it was on page 731 perhaps it's just repeating a process described numerous times before in the book and expects you to understand the general idea by now. As I said before I would think that setting the classpath comes a long time before page 731 of a Java book.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rod Hittle wrote:Change of subject. Any reason that I can't see any attachment that I have attached in a previous post.
There is not that many things to do wrong to make it not actually show up.

Can't you not simply make a post describing the different steps. You can even add some screenshots/images to the post (as I have already seen posts with images attached to it).
 
Rod Hittle
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So can you post images on this forum without having to first put the images on someplace like Photobucket so you can have a URL? As best I can tell that is the only way on this forum.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rod Hittle wrote:So can you post images on this forum without having to first put the images on someplace like Photobucket so you can have a URL? As best I can tell that is the only way on this forum.

I noticed that some of the images are hosted on other servers and others are hosted here on CodeRanch. Seems it should work using "Attachments" beneath the posting box.
 
Rod Hittle
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
another try, this time will try to attach an image using the Attachments bar button below.

ECLIPSE and adding to JAVA Build Path.jpg
[Thumbnail for ECLIPSE and adding to JAVA Build Path.jpg]
 
Rod Hittle
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, so using this attachment option you can't attach a MS WORD document. But you can put in your post a picture. Not good as I want to put in text, then a picture then some more text and so on and so forth. I guess the next best option is to host the MS WORD doc on google and put a link to it here.

This forum could do what SIMHQ does which would be so much nicer.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rod Hittle wrote:This forum could do what SIMHQ does which would be so much nicer.

You can always suggest a feature enhancement in the Ranch Office forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic