Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connectting to MS Access in Remote machine without DSN

 
Ayan Dutta
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I want to connect MS Access in a Remote machine without configuring DSN.Is it possible ?

I have connectted to MS Access in local machine without DSN.The code is like this ...
public class ConnectToMSAccess {

/**
* @param args
*/
public static void main(String[] args) {

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String myDB ="jdbc dbc river={Microsoft Access Driver (*.mdb)};DBQ=C:/data/db1.MDB";
Connection DBConn = DriverManager.getConnection(myDB,"","");
System.out.println("Connected without any DSN !!!");
}
catch(Exception e){
e.printStackTrace();

}

}

}

Now, if I know IP and full path to the MDB in the remote machine ,then is it possible to connect to a remote machine ? if possible what changes I need in the existing code ?
Regards,
Ayan
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any ODBC connection needs to be configured; it won't work without that. If you can live without JDBC access, have a look at Jackcess. It lets you access an Access DB through a direct API; file access (possibly over a shared drive) is required, though.
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On the remote machine, share the folder that contains the mdb file (in this case it would be the "data" directory). Then, just use the fully qualified path to access it.



Cheers,
[ January 31, 2006: Message edited by: Tom Blough ]
 
Ayan Dutta
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tom,
Many thanks for ur suggestion. It worked fine in windows machine.
But one thing how can I do that in a Linux machine ?
When I am running the same code that is ...

public class ConnectToMSAccess {

/**
* @param args
*/
public static void main(String[] args) {

try{


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
/*String myDB1 ="jdbc dbc river={Microsoft Access Driver (*.mdb)};DBQ=C://data//db1.MDB";*/

String myDB="jdbc dbc river={Microsoft Access Driver (*.mdb)};DBQ=//machineName/shared/db2.MDB";
Connection DBConn = DriverManager.getConnection(myDB,"","");
java.sql.DatabaseMetaData dmd = DBConn.getMetaData();

System.out.println("Connected without any DSN !!!");
}
catch(Exception e){
e.printStackTrace();

}

}

}

the follwing exception is coming :

java.sql.SQLException: [unixODBC][Driver Manager]Data source name not found, and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3074)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at ConnectToMSAccess.main(ConnectToMSAccess.java:47)

Naturally it is not getting the driver from a Linux machine ,which is there in any windows machine.Any solution ? But thanks again,for ur suggestion.
Regards,
Ayan
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can connect from a Windows machine to an MDB file that resides on a Linux machine using this method, but you cannot connect from a Linux machine to a MDB file residing on another computer this way.

This "DSN-less" connection is not really DSN-less. Instead of configuring an explicit System or Machine DSN using the ODBC manager on a Windows box, when the JDBC:ODBC bridge contacts the ODBC service with the DSN string, the ODBC service creates the connection on the fly.

Linux does not have the Windows ODBC service, so it cannot create the DSN on the fly.

Cheers,
[ February 01, 2006: Message edited by: Tom Blough ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic