aspose file tools*
The moose likes JDBC and the fly likes Connectting to MS Access in Remote machine without DSN Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connectting to MS Access in Remote machine without DSN" Watch "Connectting to MS Access in Remote machine without DSN" New topic
Author

Connectting to MS Access in Remote machine without DSN

Ayan Dutta
Ranch Hand

Joined: Oct 16, 2005
Posts: 94
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
Marshal

Joined: Mar 22, 2005
Posts: 41874
    
  63
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.


Ping & DNS - my free Android networking tools app
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
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 ]

Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
Ayan Dutta
Ranch Hand

Joined: Oct 16, 2005
Posts: 94
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

Joined: Jul 31, 2003
Posts: 263
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Connectting to MS Access in Remote machine without DSN