3

I'm trying to create ODBC linked table in an Access .mdb using Jackcess.

Final String connStr = "ODBC;DRIVER={Sybase ASE ODBC Driver};NA=dbhostname,port;DB=myDbName;UID=myID;PWD=myPass;FILEDSN=path//myDSN.dsn";

Database mdb =Database.create(new File("./test.mdb");
mdb.createLinkedTable("testLinkTable",connStr, "targetTableName");

when I open test.mdb, I can see "testLinkTable", but type of link is "Access Link". I'm expecting to create "ODBC Link" table in test.mdb.

Could somebody kindly show me the right way to accomplish this?

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
  • sometimes the easiest way to figure something out like this is to go the reverse direction. create an ODBC link using MS Access, then look at the connection string using Jackcess. then you can mimic the syntax you find. – jtahlborn Oct 09 '12 at 12:03
  • Thanks for the advice, I tried that but it did not work yet. – user1731576 Oct 09 '12 at 12:07

1 Answers1

0

It appears that the .createLinkedTable() method in Jackcess is currently only able to create links to tables in another Access database. I just tested this with Jackcess 2.0.1 and the following code successfully created an Access linked table named [Clients] that points to another Access database:

Database database = DatabaseBuilder.open(new File("C:\\__tmp\\jTest\\linkTest.accdb"));
String linkedTableLocalName = "Clients";
String linkedTableSource = "C:\\Users\\Public\\Database1.accdb";
String linkedTableRemoteName = "Clients";
database.createLinkedTable(linkedTableLocalName, linkedTableSource, linkedTableRemoteName);

However, this code created a linked table named [dbo_Addresses] that looked like a link to another Access database (not an ODBC linked table as intended) and did not work:

Database database = DatabaseBuilder.open(new File("C:\\__tmp\\jTest\\linkTest.accdb"));
String linkedTableLocalName = "dbo_Addresses"; 
String linkedTableSource = "ODBC;DSN=myDb;Trusted_Connection=Yes;APP=Microsoft Office 2010;DATABASE=myDb;";  
String linkedTableRemoteName = "dbo.Addresses";
database.createLinkedTable(linkedTableLocalName, linkedTableSource, linkedTableRemoteName);
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418