• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

classpath JDBC driver

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have installed C:\mysql-connector-java-5.1.6\mysql-connector-java-5.1.6-bin.jar containing the JDBC driver.class
When I run a certain java application I made (years ago) and press a button to submit a new record to a database I get...

Could not load JDBC driver: java.lang.ClassNotFoundException:com.mysql.jdbc.driver

Now I know I need to do something with classpath, but I don't have a CLASSPATH system variable, and I've read that I shouldn't make one either.
I've tried adding the .jar to User variable PATH but this doesn't seem to work either.

PATH C:\Program Files\Java\jdk1.6.0_23\bin;C:\mysql-connector-java-5.1.6\mysql-connector-java-5.1.6-bin.jar

NowI run the java program with a batch file which simply contains
java SchrijfNaarDatabase
should I add a -classpath instruction in this batch maybe so that the application can find the .jar file?

I've been searching for the solution on internet for many hours over many days and feel kinda foolish for not being able to work it out.
I know this app used to work in the past, but somehow it doesn't anymore.

I would greatly appreciate it if someone could give me some advice.





 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Onslow McCann wrote:should I add a -classpath instruction in this batch maybe so that the application can find the .jar file?


Definitely.
 
Onslow McCann
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply quick reply Rob,
I had tried some variations, but none seem to work really.

java -classpath C:\mysql-connector-java-5.1.6 SchrijfNaarDatabase

java -classpath C:\mysql-connector-java-5.1.6\mysql-connector-java-5.1.6-bin.jar SchrijfNaarDatabase

java SchrijfNaarDatabase -classpath C:\mysql-connector-java-5.1.6\mysql-connector-java-5.1.6-bin.jar

java SchrijfNaarDatabase -classpath C:\mysql-connector-java-5.1.6

I can't really figure out what I'm doing wrong.
versions 3 and 4 open my application allright, but still can't find the driver.


 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Versions 3 and 4 will pass the -classpath and folder / JAR file as arguments to the main method of your Java class.

Version 2 should actually work if the path is correct. Can you show us the error you're getting?
 
Onslow McCann
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Microsoft Windows XP [versie 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

Map van C:\Documents and Settings\Chris\Mijn documenten\java_2\0001Movie_databa
se_005

20-12-2011 13:28 <DIR> .
20-12-2011 13:28 <DIR> ..
20-12-2011 13:19 107 compileren.bat
20-12-2011 13:28 3.160 Database.class
02-09-2010 10:39 5.499 Database.java
20-12-2011 13:28 2.170 InpoetScreen.class
02-09-2010 11:04 2.307 InpoetScreen.java
20-12-2011 13:28 523 SchrijfNaarDatabase.class
02-09-2010 10:42 477 SchrijfNaarDatabase.java
20-12-2011 13:50 101 start.bat
9 bestand(en) 15.373 bytes
2 map(pen) 1.926.512.640 bytes beschikbaar

C:\Documents and Settings\Chris\Mijn documenten\java_2\0001Movie_database_005>st
art.bat

C:\Documents and Settings\Chris\Mijn documenten\java_2\0001Movie_database_005>ja
va -classpath C:\mysql-connector-java-5.1.6\mysql-connector-java-5.1.6-bin.jar S
chrijfNaarDatabase
Exception in thread "main" java.lang.NoClassDefFoundError: SchrijfNaarDatabase
Caused by: java.lang.ClassNotFoundException: SchrijfNaarDatabase
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: SchrijfNaarDatabase. Program will exit.
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add ";." (without the quotes) to your class path. I forgot that if you explicitly set the class path, the current folder is no longer implicitly part of the class path. It needs to be a part of the explicit class path:
java -classpath C:\mysql-connector-java-5.1.6\mysql-connector-java-5.1.6-bin.jar;. SchrijfNaarDatabase
 
Onslow McCann
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Yes!!!
Thanks a lot for your help.
Came close to quitting there for a while.
 
Everybody! Do the Funky Monkey! Like this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic