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:

Answered my own question - sort of!

Posted by Mike Bell on February 21, 2002 at 8:05 AM

Although I haven't managed to get the file DSN working correctly, I have been able to do the same thing, more or less, using a DSN-less connection & specifying everything in a connection string - the code which works is:

import java.sql.*;

public class TestAccess
{
private static String dbsrc = "jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb); " +
"DBQ=D:/projects/tacho/db/COMP150.MDB; " +
"UserCommitSync=Yes; " +
"Threads=3; " +
"SafeTransactions=0; " +
"PageTimeout=5; " +
"MaxScanRows=8; " +
"MaxBufferSize=2048; " +
"DriverId=281; " +
"DefaultDir=C:/ProgramFiles/CommonFiles/ODBC/DataSources";

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(dbsrc, "", "");

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();
}
}
}
}

For some reason, this works fine, though I would still be very interested if anyone has the answer as to how this same information can be read from the DSN file (as it should be!).

However, hopefully someone else out there will find this information useful.



Replies:

Sponsored Links



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