Jump to Real's How-to Main page

Using DSN-less connection

This HowTo seems broken, if anyone know what is problem, let me know!, Thanks
(works on some Windows installation while on other it does not!)

It is possible to connect to a database without a User or System DSN. This is useful if you don't have easy access to a client registry to define the required DSN. Not all JDBC driver support this feature.

// For Access
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String myDB =
"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/data/month.MDB";
DBConn = DriverManager.getConnection(myDB,"","");

// For Excel
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String myDB =
   "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=c:/data/month.xls;"
    + "DriverID=22;READONLY=false";
DriverManager.getConnection(myDB,"","");
Thanks to R. Hibberd for the tip.
If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2005
[ home ]