• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassNotFoundException in sun.jdbc.odbc.JdbcOdbcDriver

 
mandeep saikia
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Experts,

I am new to Java Programming and was trying to connect my app with the MS Access DB (JDBC:ODBC Driver)...however, all I am getting are exceptions....

[ I have my classpath variable already set...also have one of the paths set to rt.jar ]

My code is--

 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch. Post the full text of all error message and exceptions you get. Even better, post the entire stack trace - you get those by putting "e.printStackTrace()" in the catch block.

also have one of the paths set to rt.jar

You didn't say what "one of the paths" is, exactly, but you don't need to do anything with rt.jar. In fact, you should not do anything with it.
 
mandeep saikia
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick response Sir...

Sir, with printStackTrace() method ..i am getting --

java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:30
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:259)
at sample.<init>(sample.java:8)
at sample.main(sample.java:21)


Thanks,

Mandeep
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using Java 8 by any chance? It does not contain the JDBC/ODBC driver. You'll have to use a commercial driver like HXTT, or a library like Jackcess.

Alternatively, you can use one of the many databases for which free JDBC drivers are available, like MySQL, PostgreSQL, SQLServer etc.
 
Paul Clapham
Sheriff
Posts: 21554
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using Java 8? The JDBC-ODBC bridge functionality has been removed from that version. If that's the case, then have a look at this Ranch thread on that subject from last year:

http://www.coderanch.com/t/609838/java/java/Removal-JDBC-ODBC-Bridge-Java
 
mandeep saikia
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Sir...I was using java 8...

Sorry !!! I should have looked into it before...Thanks !!!

I will try to use Jackcess API to connect to the Access DB...Hope that works
 
Paul Clapham
Sheriff
Posts: 21554
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need to apologize, it's very unusual for Oracle to remove features from Java so you shouldn't have been expected to anticipate that. Anyway, it looks like you're on the road to finding an alternate solution, so that's good.
 
mandeep saikia
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sir,

I have downloaded the jackcess-2.0.4.jar and set the classpath...!!

To test things, I wrote few lines of code to access an existing MS Access database, to test the jackcess APIs...however, during compilation I am getting errors--

jdbc.java:7: error: package com.healthmarketscience.jackcess does not exist
import com.healthmarketscience.jackcess.*;
^
jdbc.java:14: error: cannot find symbol
Table t1 = DatabaseBuilder.open(f1).getTable("student");
^
symbol: class Table
location: class Jdbc1
jdbc.java:14: error: cannot find symbol
Table t1 = DatabaseBuilder.open(f1).getTable("student");
^
symbol: variable DatabaseBuilder
location: class Jdbc1
3 errors

Is there a problem with setting classpaths with com.* packages?

Please help.

Thanks in advance.

Mandeep
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How have you added the jar file to the classpath? I generally recommend not to use the CLASSPATH environment variable, but rather the "-cp" switch.
 
mandeep saikia
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sir,

Sir..actually this is a compile time error..apologies..but not a classpath problem i think...


D:\mandeep>javac jdbc.java
jdbc.java:7: error: package com.healthmarketscience.jackcess does not exist
import com.healthmarketscience.jackcess.*;
^
jdbc.java:14: error: cannot find symbol
Table t1 = DatabaseBuilder.open(f1).getTable("student");
^
symbol: class Table
location: class Jdbc1
jdbc.java:14: error: cannot find symbol
Table t1 = DatabaseBuilder.open(f1).getTable("student");
^
symbol: variable DatabaseBuilder
location: class Jdbc1
3 errors

In eclipse I am getting the following error log ::-

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/builder/StandardToStringStyle
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:455)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.healthmarketscience.jackcess.impl.ColumnImpl$SortOrder.toString(ColumnImpl.java:2215)
at java.lang.String.valueOf(String.java:2979)
at java.lang.StringBuilder.append(StringBuilder.java:131)
at com.healthmarketscience.jackcess.impl.IndexData.newColumnDescriptor(IndexData.java:1303)
at com.healthmarketscience.jackcess.impl.IndexData.read(IndexData.java:435)
at com.healthmarketscience.jackcess.impl.TableImpl.readIndexDefinitions(TableImpl.java:1342)
at com.healthmarketscience.jackcess.impl.TableImpl.<init>(TableImpl.java:261)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.readTable(DatabaseImpl.java:1437)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.readSystemCatalog(DatabaseImpl.java:800)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.<init>(DatabaseImpl.java:517)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.open(DatabaseImpl.java:390)
at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:170)
at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:193)
at javajdbc.Jdbc1.main(Jdbc1.java:14)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.builder.StandardToStringStyle
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 26 more

Please help!!

Thanks in advance.

Regards,

Mandeep
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
D:\mandeep>javac jdbc.java

As I said, I advise to use the "-cp" switch for adding libraries to the classpath.

Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.builder.StandardToStringStyle

The Commons Lang library is apparently one of the dependencies; check out http://jackcess.sourceforge.net/dependencies.html for what else is needed.
 
mandeep saikia
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sir,

I have downloaded and added all the JARs (ALL) dependencies (i.e. commons-lang + commons-logging) and added all of them to eclipse built-path-->Add External Archives..

But still in runtime...Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/builder/StandardToStringStyle
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:455)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.healthmarketscience.jackcess.impl.ColumnImpl$SortOrder.toString(ColumnImpl.java:2215)
at java.lang.String.valueOf(String.java:2979)
at java.lang.StringBuilder.append(StringBuilder.java:131)
at com.healthmarketscience.jackcess.impl.IndexData.newColumnDescriptor(IndexData.java:1303)
at com.healthmarketscience.jackcess.impl.IndexData.read(IndexData.java:435)
at com.healthmarketscience.jackcess.impl.TableImpl.readIndexDefinitions(TableImpl.java:1342)
at com.healthmarketscience.jackcess.impl.TableImpl.<init>(TableImpl.java:261)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.readTable(DatabaseImpl.java:1437)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.readSystemCatalog(DatabaseImpl.java:800)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.<init>(DatabaseImpl.java:517)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.open(DatabaseImpl.java:390)
at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:170)
at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:193)
at javajdbc.Jdbc1.main(Jdbc1.java:19)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.builder.StandardToStringStyle
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

I dont know what to do?



Regards,

Mandeep
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have downloaded and added all the JARs (ALL) dependencies (i.e. commons-lang + commons-logging) and added all of them to eclipse built-path-->Add External Archives..

But still in runtime...Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/builder/StandardToStringStyle


Make sure you add all libraries to both build path and runtime path - those are different.
 
mandeep saikia
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sir,

As far as i know ..adding jars to build path in eclipse takes care of the compilation... however, have no idea how to add JARs to runtime path...??

Is it available in the eclipse documentation ..please guide me Sir how to add them to runtime path!!


Thanks again.

Regards,

Mandeep
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No idea. Searching for "adding libraries eclipse runtime path" or some such phrase should get you started. Or ask in the IDE forum, as this has nothing to do with JDBC.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic