The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
February 2002

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

jdbc-odbc bridge using a file DSN with MS Access on Win2K

Posted by Mike Bell on February 21, 2002 at 4:47 AM

I'm having problems using the jdbc-odbc bridge with an MS Access database and a file DSN. If I use a system DSN, it works fine but it does not seem to find the file DSN for some reason (And I HAVE to use a file DSN in this instance, for reasons I won't bore you with) - this is the error-message:

"java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"

This is my example code:

import java.sql.*;

public class TestAccess
{
private static Connection conn;
private static Statement stmt;
private static ResultSet results;

public static void main(String[] args)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

conn = DriverManager.getConnection("jdbc:odbc:test", "", "");

stmt = conn.createStatement();
results = stmt.executeQuery("SELECT * FROM vehicle");

while(results.next())
{
System.out.println(results.getString("reg"));
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
results.close();
stmt.close();
conn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
}

The file DSN was set up using the Win2K ODBC administrator and it is in the default location of:

C:\ProgramFiles\CommonFiles\ODBC\DataSources

and is called "test.dsn" - it looks like this:

[ODBC]
DRIVER=Driver do Microsoft Access (*.mdb)
UID=admin
UserCommitSync=Yes
Threads=3
SafeTransactions=0
PageTimeout=5
MaxScanRows=8
MaxBufferSize=2048
FIL=MS Access
DriverId=281
DefaultDir=D:\projects\tacho\db
DBQ=D:\projects\tacho\db\COMP150.MDB

And the COMP150.MDB file is in the location specified in the DBQ= property.

Why can't ODBC find this DSN, when it's fine with a system DSN? Is there something in my naming syntax that's wrong, or do I need to tell ODBC it's using a file DSN in some way?

I'd be very grateful for any/all assistance. Thanks.



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us