Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JDBC & MS Access

0 views
Skip to first unread message

Tim

unread,
Aug 4, 1999, 3:00:00 AM8/4/99
to
Can anybody give me a general idea of how to use jdbc to connect to a
MS Access db? I'm doing this to learn the jdbc and also more generally
how to access dbs over a network.

I've got an access db on a unix box (server) that I can get rw
permissions for. I'll be using a Windows 98 system and jdk1.2.2 on the
client side.

The part of the process that really has me buggered is that I don't
understand the actual odbc dsn issues at a very fundamental level.

Thanks for the help,

Tim


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

Nathan Sandland

unread,
Aug 4, 1999, 3:00:00 AM8/4/99
to timbr...@mindspring.com

I am uncertain, but do not think it would be very easy to set up access on
unix as a JDBC source. There are many variables to consider in using a
database server from within a windows emulator. I even doubt that windows'
ODBC will work. I would recommend setting your project up on a true
windows machine, then migrating to the Unix box once the windows box works,
if you really must use access on Unix.

On the windows machine, you can set up Sun's JDBC-ODBC bridge if and only
if the client and server run on the same machine. Otherwise you will need
middleware, such as Symantec's dbAnywhere.

If you really have to use unix, but are not bound to MS Access, you should
use another DBMS. There are a few freeware DBMS's which have JDBC
drivers. Off the top of my head, MySQL and mSQL are two.
--

Nathan Sandland

Reuse Engineer
Motorola Cellular Subscriber Sector
sand...@urbana.css.mot.com
(217)384-8568

Mild

unread,
Aug 5, 1999, 3:00:00 AM8/5/99
to
Hi:

Unfortunately, when I try and connect to the database thru IE50(using JDK1.2
Plug in) in an applet, I always get an

No suitable driver

error message even though I have a datasource setup for it...

As a stand-alone (non applet), it always works and is able to connect...

I have my data source registered and all.. For some reason, it just won't
work in an applet:
If you see anything I'm doing wrong, please let me know as this has been
bugging me...
It fails (as an applet) in the forName statement...
-----------------------------------------------
My output is always:
test_LoadDriver...
directeldb.test_LoadDriver failed
Forname succeeded
connectToURL(), url = jdbc:odbc:hdcm;UID=Test;PWD=Test
connectToURL() failed
init_DBConnection Exception: No suitable driver
Cannot initialize the DB Connection..
java.security.AccessControlException: access denied
(java.lang.RuntimePermission exitVM )
at java.security.AccessControlContext.checkPermission(Compiled Code)
at java.security.AccessController.checkPermission(Compiled Code)
at java.lang.SecurityManager.checkPermission(Compiled Code)
at java.lang.SecurityManager.checkExit(SecurityManager.java:756)
at java.lang.Runtime.exit(Runtime.java:81)
at java.lang.System.exit(System.java:626)
at JMain.init(JMain.java:54)
at sun.applet.AppletPanel.run(Compiled Code)
at java.lang.Thread.run(Thread.java:479)
------------------------------------------


public boolean initTestDBConnection()
{
dtLog.log("test_LoadDriver...", dtLog.DEBUG);
//
// This is the name of the datasource!!!
//
m_bLastError = false;
boolean ret = true;

try {
String accDriver = "sun.jdbc.odbc.JdbcOdbcDriver";

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
}
catch(Exception e) {
m_bLastError = true;
ret = false;
dtLog.log("directeldb.test_LoadDriver failed", dtLog.EVENT);
}
dtLog.log("Forname succeeded", dtLog.EVENT);
String m_sConnUrl = new String("jdbc:odbc:hdcm;UID=Test;PWD=Test");
return connectToURL(m_sConnUrl, false);
}


private boolean connectToURL(String sInUrl, boolean bTest)
{
dtLog.log("connectToURL(), url = " + sInUrl, dtLog.DEBUG);

try {
if (bTest == false)
m_dbConn = DriverManager.getConnection(sInUrl);
else
m_dbConn = DriverManager.getConnection(sInUrl, "Test",
"Test");

}
catch(Exception e) {
m_bLastError = true;
dtLog.log("connectToURL() failed", dtLog.EVENT);
m_dbConn = null;
String sMsg = "init_DBConnection Exception: " +
e.getMessage();
dtLog.log(sMsg, dtLog.EVENT);
return false;
}

return true;
}

Thomas Binkert

unread,
Aug 6, 1999, 3:00:00 AM8/6/99
to timbr...@mindspring.com
use that jdk's jdbc-odbc driver... and register the access database
in the odbc-data soucres tool on billy's control pannel....
or use a better database supporting directly jdbc drivers!!

// Register JDBC/ODBC Driver in jdbc DriverManager
// On some platforms with some java VMs, newInstance() is necessary...
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
// Test with MS Access database (rjdemo ODBC data source)
String url = "jdbc:odbc:database";
java.sql.Connection c = DriverManager.getConnection(url,"admin", "admin");

Eric Kramer

unread,
Aug 8, 1999, 3:00:00 AM8/8/99
to
Tim,
Keep in mind that MSAccess databases aren't "client/server" so you won't need the unix box (unless you're
using it as a file (vs. database) server.

To answer (hopefully) your DSN question... You'll want to open a connection using the Jdbc-Odbc bridge
driver that Sun supplies as part of java. It will allow you to access all of your installed ODBC datasources
(including MSAccess). Try searching the java.sun.com site (or a good java book) for info about the Jdbc/Odbc
bridge driver. Good luck!
Eric

0 new messages