Trouble with .mdbAny help is apreciated

Hi

I need to access an .mdb file.

Im trying to make a program that will allow me to extract the data from the .mdb and place it in a SQL database.

The code below results in a java.sql.SQLException: No suitable driver.

I've tried putting all sorts of things into the DriverManager.getConnection(), but I haven't been able to make it work.

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

/* MDBReader.java

* Created on 3. oktober 2006, 13:16

* @author Leviathan

*/

publicclass MDBReader

{

/** Creates a new instance of MDBReader */

public MDBReader()

{

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con = DriverManager.getConnection(""+this.getClass().getResource("OtraLink.mdb"));

Statement stm = con.createStatement();

ResultSet rs = stm.executeQuery("select * from *");

System.out.println(rs.toString());

con.close();

}

catch (ClassNotFoundException ex)

{

ex.printStackTrace();

}

catch(SQLException ex)

{

ex.printStackTrace();

}

}

publicstaticvoid main(String[] args)

{

MDBReader mdbReader =new MDBReader();

}

}

I've spent the better part of a day browsing this forum and google, but I have nothing to show for it.

Any help will be apreciated.

[2504 byte] By [Leviathana] at [2007-10-3 6:24:50]
# 1

I have no idea what you are doing with that getClass().getResource() bit but I can assure you that that is NOT a valid JDBC url whatever it is.

Your connection url should look something like

"jdbc:odbc:DSN_NAME_HERE"

Or replace the name with the appropriate dynamic DSN string.

You aren't trying to use an mdb stored in a Jar are you? I mean the URL is dead wrong anyway but you won't be able to do that no matter what you do if that is your intent.

cotton.ma at 2007-7-15 1:10:44 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

the getClass().getResource()

is simply because my ,mdb-file is located in the same package as my code, hence it will also be in my Jar.

I know this might sound like a dumb question, but exactly what is "DSN_NAME_HERE" ? I mean, what is DSN?

I tried writing jdbc:odbc:sms

(saw it in a post) but that didn't work.

Leviathana at 2007-7-15 1:10:44 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
i don't think the database can be in the JAR.google or search this forum for DNS-less connection string.%
duffymoa at 2007-7-15 1:10:44 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

>is simply because my ,mdb-file is located in the same package as my code,

> hence it will also be in my Jar.

For jdbc-odbc bridge, it's impossible. You should unjar first that mdb file into a temporary directory, then use dns-less url.

For commercial HXTT Access jdbc driver for MS Access, which supports compressed database(.ZIP, .JAR, .GZ, .TAR, .BZ2, .TGZ, .TAR.GZ, .TAR.BZ2), you should read How to Use Memory-only Table, Physical Table, Url table, Compressed table in a SQL at http://www.hxtt.com/dbf/advanced.html#mining .

zhaoyha at 2007-7-15 1:10:44 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...