odbc driver

I'm trying to connect to an Access database (which resides on my hard-drive as a *.mdb file.) I'm doing Java work on a Fedora Core 5 box in eclipse. I keep getting an error saying the below:
Exception in thread "main" java.lang.ClassNotFoundException: sun.jdb.odbc.JdbcOdbcDriver not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:/lhome/******/workspace/testAccessDBRead/], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URLClassLoader.findClass (libgcj.so.7)
at java.lang.ClassLoader.loadClass (libgcj.so.7)
at java.lang.ClassLoader.loadClass (libgcj.so.7)
at java.lang.Class.forName (libgcj.so.7)
at java.lang.Class.forName (libgcj.so.7)
at testAccessDBRead.main (testAccessDBRead.java:12)
This is my code.
import java.sql.*;

public class testAccessDBRead
{
public static void main(String[] args) throws Exception
{
final String DRIVER_NAME = "sun.jdbc.odbc.JdbcOdbcDriver";
final String dbURL = "jdbc:odbc:testDB";

Class.forName(DRIVER_NAME);

Connection connection = null;
Statement statement = null;
ResultSet resultSet = null

try
{
connection = DriverManager.getConnection(dbURL);
statement = connection.createStatement();
resultSet = statement.executeQuery("SELECT * FROM NameTable");

while(resultSet.next())
{
System.out.println(resultSet.getString(1));
}
}
catch(Exception e)
{
System.out.println("Error in main:");
System.out.println(e.getMessage());
}
finally
{
try
{
resultSet.close();
statement.close();
connection.close();
}
catch(Throwable ignore)
{
}
}
}
}
I got the code from the below thread and thought of trying it out in order to make it work for me.

http://www.dev-archive.com/forum/showthread.php?t=382347&highlight=access+database

Anyone know what I'm doing wrong? I haven't touched Java for some time, soo...
[2122 byte] By [YourSurrogateGod] at [2007-11-19 23:53:50]
# 1 Re: odbc driver
It's an Access 95 database, FYI.
YourSurrogateGod at 2007-11-10 2:18:55 >
# 2 Re: odbc driver
Have you downloaded the JDBC-ODBC driver and added the same to your classpath ? If not do it and then try.
tbear at 2007-11-10 2:19:55 >
# 3 Re: odbc driver
I'm not sure as to how I can even check whether I have that driver.
YourSurrogateGod at 2007-11-10 2:20:54 >
# 4 Re: odbc driver
The driver usually comes with the JDK/JRE you download from sun. You should automatically have it, where did you get your JDK from?
Bnt at 2007-11-10 2:22:04 >
# 5 Re: odbc driver
The driver usually comes with the JDK/JRE you download from sun. You should automatically have it, where did you get your JDK from?
The Fedora Core 5 CD that I used to install Linux. I'm wondering how I could open up that Access 95 *.mdb file and read out its contents.
YourSurrogateGod at 2007-11-10 2:23:03 >
# 6 Re: odbc driver
I think you should maybe download a JDK from java.sun.com and use that one.
Bnt at 2007-11-10 2:24:03 >
# 7 Re: odbc driver
I think you should maybe download a JDK from java.sun.com and use that one.
I'm guessing that the one from Sun already has all of those things in there?
YourSurrogateGod at 2007-11-10 2:25:06 >
# 8 Re: odbc driver
Yes it does.
Bnt at 2007-11-10 2:26:01 >
# 9 Re: odbc driver
Try sun.jdbc.odbc.JdbcOdbcDriver. If that doesn't work, and you have multiple versions of java on your machine, make sure it is using the correct one.
spidermo at 2007-11-10 2:27:09 >
# 10 Re: odbc driver
Try sun.jdbc.odbc.JdbcOdbcDriver. If that doesn't work, and you have multiple versions of java on your machine, make sure it is using the correct one.
I'm already using that.

Ok, now that I finally can spend more time on this, I've made sure that I do infact have the latest Java JDK/JRE 5.0. So versions shouldn't be a problem. I'm doing this in eclipse in linux, further FYI, but I don't think that this will make a difference.

Pretty much I'm trying to open that *.mdb file.

Here is the stack trace and the warning message after everything has been updated and such.
Error:
Error in executeAccess
Error message:
[unixODBC][Driver Manager]Data source name not found, and no default driver specified
Stack trace:
java.sql.SQLException: [unixODBC][Driver Manager]Data source name not found, and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3074)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at DBConverter.connectAccess(DBConverter.java:33)
at DBConverter.main(DBConverter.java:129)
I've also attached the source file so that it would be easy for everyone to download it.
YourSurrogateGod at 2007-11-10 2:28:10 >
# 11 Re: odbc driver
Have you created the ODBC connection to your .mdb file? In windows you would go to your ODBC manager and set one up, not sure how you would do it on Linux.
Bnt at 2007-11-10 2:29:13 >
# 12 Re: odbc driver
Ok, I've taken a few steps back and ensured that the Java SDK works fine on my PC. When I do the below, I get no output, which suggests to me that it works fine.
class Test
{
public static void main(String[] args)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (Exception e)
{
System.out.println("Error: " + e);
}
}
}
However, when I try to execute the below program...
import java.sql.*;
class Test
{
public static void main(String[] args)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String filename = "/path/to/mdbTEST.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
Connection con = DriverManager.getConnection( database ,"","");
}
catch (Exception e)
{
System.out.println("Error: " + e);
}
}
}
... the error print out is...
Errors:
The error message.
null
The stack trace.
My question is. Why does it print out null as an error? That type of an error thrown doesn't make any sense.
YourSurrogateGod at 2007-11-10 2:30:12 >
# 13 Re: odbc driver
For further clarification, that error is something that I get while running the program.

Also, does anyone know under which circumstances I might get a null for an error thrown?
YourSurrogateGod at 2007-11-10 2:31:13 >
# 14 Re: odbc driver
Ok, I just read this ( http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Exception.html#Exception()) about how the error message is uninitialized. What the heck does this mean?
YourSurrogateGod at 2007-11-10 2:32:10 >
# 15 Re: odbc driver
I've never seen an error printout like that - it's even added an 's' on the end of 'Error' on the first line! Looks like someone has written an Exception class that won't output a sensible message or stack trace...

Or is it just that you haven't bothered to copy and paste the full error text? If so, you shouldn't expect too much if you don't provide all the relevant information.

You could try calling printStackTrace(), getCause(), and getMessage() to see if anything more useful appears. Catching the specific exception classes that may be thrown helps locate the problem.

Optimism is an occupational hazard of programming: testing is the treatment...
K. Beck
dlorde at 2007-11-10 2:33:14 >
# 16 Re: odbc driver
Ok, I just read this (http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Exception.html#Exception()) about how the error message is uninitialized. What the heck does this mean?It means that if an Exception is created via the default (no-argument) constructor, the error message isn't set. How could it be if one isn't provided? This situation is usually due to an internal exception type being caught in the driver and converted to a more generic exception to be thrown on. The generic exception isn't always given a message, so it is expected that the original 'cause' exception will be passed to the generic exception via the initCause(..) method.

I suggest you try calling getCause() to see if there's a Throwable (exception) inside that can give you an error message.

The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time...
T. Cargill
dlorde at 2007-11-10 2:34:18 >