Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

dsn-less connection

  Asked By: Ayden    Date: Nov 27    Category: Java    Views: 1644
  

Can anyone tell me how the source
code to create a dsn-less connection to a Microsoft
Access 2000 database called "Test" (using the source
code rather than the control panel to setup the
database).So far I have found this code, it compiles but when
I run it I get the following error
message:Connection Exception: java.sql.SQLException:
[Microsoft][ODBC Microsoft Access Driver] Could not find file
'(unknown)'.Could anyone tell me whats wrong and how to fix it
please.-----------------------Code:import
java.sql.*;public class
MakingTheConnection3 { public static void main(String[] args)
{Connection connection; Statement statement; String
url = System.getProperty("user.dir") +
"\\catalogo.mdb"; String conStr = "jdbc:odbc:Driver={Microsoft
Access Driver (*.mdb)};DBQ=" + url; try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); connection =
DriverManager.getConnection(conStr); connection.createStatement(); }
catch
(Exception ex){ System.out.println("Connection
Exception: " + ex); } }}

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Phoebe Brown     Answered On: Nov 27

What does your url String look like if you do a
System.out.println(url)? Does it look like a path to a valid
file?It appears your connect string is OK with finding
the driver, but not able to find the
file...I've done DNS"less" connections in VB and C++, but not
in Java... for some reason it just didn't work (lack
of patience in the devloper, probably). You seem to
be on the right track, but just check the value of
your "url".Sorry that I couldn't be of more
help, but I haven't use MS Access for database in
years.Stephen McConnellhttp://www.crosslogic.com

 
Didn't find what you were looking for? Find more on dsn-less connection Or get search suggestion and latest updates.




Tagged: