3

I have to define a new Driver in the Netbeans "Services" Tab
Services->Databases->Drivers->new Driver...
because I want use the "Entity Classes from Database"-Wizard in context with UCanAccess.
1st step: "new Driver" does work (only declaration ;-) )

  • Driver File(s): f:\WorkspaceNetbeans\MSAccessDB\lib\UCanAccess-2.0.4-bin\ucanaccess-2.0.4.jar
  • Driver Class: net.ucanaccess.jdbc.UcanaccessDriver
  • Name:msaccess

2nd step: "Connect using..."

  • JDBC URL: jdbc:ucanaccess://F:/WorkspaceNetbeans/MSAccessDB/data/Datenbank2.accdb
  • "User Name" and "Password" leave blank

The "Test Connection"-Button results in Error Message:

Cannot establish a connection to jdbc:ucanaccess://F:\WorkspaceNetbeans\MSAccessDB\data\Datenbank2.accdb using
net.ucanaccess.jdbc.UcanaccessDriver (Could not initialize class
net.ucanaccess.jdbc.UcanaccessDriver)

I've got the newest ucanaccess from http://ucanaccess.sourceforge.net/site.html ucanaccess-2.0.4.jar, commons-lang-2.6.jar, commons-logging-1.0.4.jar, hsqldb.jar, jackcess-2.0.3.jar in the Netbeans Classpath.

The old fashion way to connect via jdbc to ucanaccess works fine.

public static void main(String[] args) throws ClassNotFoundException, SQLException {
   String connectString = "jdbc:ucanaccess://" + "f:/WorkspaceNetbeans/MSAccessDB/data/Datenbank2.accdb";
   Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
   Connection conn = DriverManager.getConnection(connectString, "", "");
   conn.createStatement().execute("CREATE TABLE example1 (id COUNTER PRIMARY KEY,descr text(400), number numeric(12,3), date0 datetime) ");
}

The same connection string also works fine make DBeaver able to connect to the MSAccess db.

My set up:
Windows 7 Professional 64 bit
Microsoft Office 2013
NetBeans IDE 8.0
Java 1.8

The problem is similar to: "Conflict between JT400 and UCanAccess?" Conflict between JT400 and UCanAccess?
but the answers there don't help with my problem.

Any ideas to solve my problem?

  • 1
    I was able to recreate the issue on Win8.1_Pro 32-bit, NetBeans IDE 8.0, JDK 1.7, UCanAccess and Jackcess both version 2.0.4 – Gord Thompson Apr 21 '14 at 13:14
  • 1
    I'm working on this tricky problem which seems to be netbeans related. All dependencies (commons-lang-2.6.jar, commons-logging-1.0.4.jar, hsqldb.jar, jackcess-2.0.3.jar) should be listed, as well as the ucanaccess.jar, as driver files... but still I'm facing with a further issue. I hope let you know my findings asap. – jamadei Apr 21 '14 at 18:06

2 Answers2

2

UCanAccess 2.0.4.1 has been released, now you can configure UCanAccess as NetBeans service. As explained in the UCanAccess web site (tab 'jdbc client tools') you have to:

-in the field Driver File(s), add ucanaccess.jar and all dependencies. I've upgraded the commons-logging in the UCanAccess distribution to the 1.1.1, so you can use that jar with NetBeans8.

-use the following pattern for the jdbc url: jdbc:ucanaccess://;showschema=true Showschema connection property must be setted to true.

jamadei
  • 1,700
  • 9
  • 8
  • I tested the new version and the connection to db works. – Martin Kehrholff Apr 28 '14 at 17:08
  • Also the wizard to generate entity classe works partly. But may be there is another issue in the metadata, because the generated classes has no relations like lists of the related tables (classes). And the reference to another table has only the ID and not the other table as a class. I know the right behaviour from using this wizard in context with a oracle database. – Martin Kehrholff Apr 28 '14 at 17:18
  • Okey, I'm going to analyze the reasons of this behavior. I'll let you know ASAP. – jamadei Apr 28 '14 at 17:52
  • a little hint: when the wizard is started, and the "Database Connection" ist selected, you have to select the tables which should be converted to entity classes. If you select a table which has relations and the "Include Related Tables" check box is selected, the related tables should be added to. – Martin Kehrholff Apr 28 '14 at 21:04
  • Yes, now (after having re-patched UcanAccessMetaData), if I select the table with the Foreign Key, I can see the related table added. After that I can see the OneToMany and ManyToOne annotations in the code of the generated entities. You can find patched code in the svn trunk (if you want to rebuild the ucanaccess.jar): http://sourceforge.net/p/ucanaccess/code/HEAD/tree/ucanaccess/trunk/src/main/java/net/ucanaccess/jdbc/UcanaccessDatabaseMetadata.java. UCanAccess 2.0.5 will be released in May. – jamadei Apr 29 '14 at 16:07
  • UCanAccess 2.0.5 has been released: now the further issue mentioned above should be fixed. – jamadei May 03 '14 at 09:48
1

I was wrong, it wasn't a tricky task but... To establish the connection you have to list in the Driver File(s) : ucanaccess-2.0.4.jar, commons-lang-2.6.jar, hsqldb.jar, jackcess-2.0.3.jar AND a different version of commons-logging that you can find it in NetBeans: NetBeans 8.0\ide\modules\org-apache-commons-logging.jar (the commons-logging in the UCanAccess distribution is in conflict with that used by NetBeans)

But unfortunatly, after establishing the connection, you won't be able to execute queries through this IDE, because of a trivial bug in the UcanaccessDatabaseMetadata which hasn't effect with the other IDE jdbc clients I tested (Openoffice, Libreoffice, DBeaver, Squirrel, SQLeo and so on) . So, to do this, you have to wait some days (I think I'll post a patched Ucanaccess 2.0.4.1 next week). Also, I'll add a note about UCanAccess configuration as NetBeans service in the UCanAccess web site.

jamadei
  • 1,700
  • 9
  • 8