Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Please Help

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right now I have a class "ShowDataBase" which create a connection to mySQL database. So I put mysql-connector-java-3.1.10-bin.jar and ShowDataBase.class together in one directory. When I run java ShowDataBase,it shows following:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
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)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at ShowDataBase.main(ShowDataBase.java:30)


however, if I run "java -cp mysql-connector-java-3.1.10-bin.jar ShowDataBase", it displays:

Exception in thread "main" java.lang.NoClassDefFoundError: ShowDataBase

I am sure the ShowDataBase run correctly until Ecipse and contains no error.
Please help me out for this problem. I don't want to run it under Eclipse very time because it takes a lot memories....
Thx a lot.
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Either add the JAR to your classpath or run it using the -cp and include ShowDatabase in the classpath as well as the JAR.
 
Wilson Oak
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry I don't get it... do you mean this?

java -cp mysql-connector-java-3.1.10-bin.jar;ShowDataBase ShowDataBase

it doesn't work too

thanks
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Wilson Oen:
sorry I don't get it... do you mean this?

java -cp mysql-connector-java-3.1.10-bin.jar;ShowDataBase ShowDataBase

it doesn't work too

thanks



I would have thought an SCJP would have classpath basics down. That would only work if ShowDataBase was in the default package and in the current directory. The -cp sets the CLASSPATH and the environment variable is NOT used. If you don't understand how to setup your classpath then I suggest getting an introductory book or looking at a tutorial. Here's something Google quickly turned up but I don't know how good it is:

http://mindprod.com/jgloss/classpath.html
 
Wilson Oak
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That works! I forget to a dot in the class path therefore it shows NoClassDefFoundError.

You are right, I depends on the IDE too much as I forget the most basic thing.

Thanks, Ken.
 
bacon. tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic