• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.NoClassDefFoundError when executing the Java class  RSS feed

 
Sachin Singh Bg
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am a beginner to java. I am trying to execute a simple java program through command prompt but I am getting a java.lang.NoClassDefFoundError. I am using jdbc oracle driver to connect to database and execute a delete statement. I have downloaded the JAR file for Oracle driver. I was able to compile the code without any issues. Below is the code snippet:



The command i am using to execute the code is java -cp ojdbc14.jar JDBCExample

Please let me know what might be causing this error.
 
sai rama krishna
Ranch Hand
Posts: 536
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you post complete error log if possible
 
Rohan Deshmkh
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Haven't seen your code, but try import instead of Import as Java is case-sensitive.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Import for import would not cause the error complained of; it would cause a compiler error.
I presume you have been through the Oracle handbook for how to connect the database to Java and how to set the classpath.

And welcome to the Ranch
 
Sachin Singh Bg
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still the issue persists and none of the solutions provided has worked out for me. Can anyone help me on this. Let me know if there are any tutorial available on JDBC basics.
 
Sachin Singh Bg
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sai rama krishna wrote:can you post complete error log if possible


Below is the error log:

C:\Documents and Settings\896033\My Documents\Bhanuprakash\Screw>java -cp ojdbc1
4.jar JDBCExample
Exception in thread "main" java.lang.NoClassDefFoundError: JDBCExample

 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only thing you're putting on the classpath is the Oracle JDBC driver JAR. You'll have to add the directory that your own class is in to the classpath too.

If your class is not in a package (there is no package statement in the source file), and you have the *.class file in the current directory, then this should work:

java -cp ojdbc14.jar;. JDBCExample

Note the ;. at the end of the classpath. That adds the current directory, denoted by ., to the classpath.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!