• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Need help with my first JDBC program

 
Ranch Hand
Posts: 96
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I am trying to write a standalone java class (with main function) to understand the working of JDBC. I have downloaded the MySQL installer for Windows from the mysql site and installed it. Now I am trying to run the following code to see if a successful connection is being made.



It compiles fine, but at runtime, throws an exception
java.lang.ClassNotFoundException : com.mysql.jdbc.Driver

Can anyone please point out what I need to do? My guess is, either my class name in incorrect, or I need to put the mysql jar in a particular folder. Which one is it? Also, this code above is not written by me. I got it from a tutorial site. Hence, is it possible that the values of

are incorrect for my particular case?
 
author & internet detective
Posts: 42154
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. You need to put that jar in your classpath. Since your program is being run at the command line, you can type "java -cp /path/to/jar FirstExample"
 
Souvvik Basu
Ranch Hand
Posts: 96
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a variable named Path = C:\Program Files (x86)\Java\jdk1.6.0_21\bin
I have another variable named JAVA_HOME = C:\Program Files (x86)\Java\jdk1.6.0_21

I have kept the jar in both the above folders, and also inside folder C:\Program Files (x86)\Java\jdk1.6.0_21\lib.

My java file is in the same place where I have all my other java files. And then I use the commands
javac FirstExample.java
java FirstExampe

The error is still there.

Can you please tell me where exactly you want me to put it, apart from these places? I must mention that I do not have any environment variable called CLASSPATH, and this hasn't prevented me from running my other java files successfully.
 
Jeanne Boyarsky
author & internet detective
Posts: 42154
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:Yes. You need to put that jar in your classpath. Since your program is being run at the command line, you can type "java -cp /path/to/jar FirstExample"



Repeating this answer. The JDBC jar you mentioned needs to be in your environment CLASSPATH variable or the -cp argument and the command line. Non-JDBC programs would work just fine.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic