UCanAccess驱动程序在尝试连接Access数据库时抛出异常,而Jackess连接工作正常



1)此UCanAccess示例代码适用于数据库A(Access 2000)

Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
            Connection conn = DriverManager.getConnection(DATABASE_URL);
            System.out.println(conn);

2) 相同的UCanAccess示例代码不适用于数据库B(Access 2000),并导致以下异常堆栈跟踪:

net.ucanaccess.jdbc.UcanaccessSQLException
    at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:247)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:233)
    at XXXXXXXXXX.JdbcAccessConnection.main(JdbcAccessConnection.java:23)
Caused by: java.lang.NullPointerException
    at net.ucanaccess.converters.UcanaccessTable.getIndexes(UcanaccessTable.java:74)
    at net.ucanaccess.converters.LoadJet$TablesLoader.loadTableIndexesUK(LoadJet.java:794)
    at net.ucanaccess.converters.LoadJet$TablesLoader.createIndexesUK(LoadJet.java:835)
    at net.ucanaccess.converters.LoadJet$TablesLoader.loadTables(LoadJet.java:921)
    at net.ucanaccess.converters.LoadJet$TablesLoader.access$3(LoadJet.java:919)
    at net.ucanaccess.converters.LoadJet.loadDB(LoadJet.java:1311)
    at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:236)
    ... 3 more

3) 下面的Jackess示例代码与数据库B(UCanAccess无法与之一起工作)一起工作,并导致以下输出

        Table table = DatabaseBuilder.open(new File(DATABASE_FILE_PATH)).getTable(tableName);
        for (Column column : table.getColumns())
        {
            System.out.println("Column " + column);
        }

输出:

Column TextColumn@9234336[
  name: (XXXXXXXXXXXXX) Table
  type: 0xa (TEXT)
  number: 0
  length: 100
  variableLength: true
  compressedUnicode: true
  textSortOrder: SortOrder[1033(0)]
]
Column Column@dc8092a[
  name: (XXXXXXXXXXXXX) Attached
  type: 0x1 (BOOLEAN)
  number: 1
  length: 1
  variableLength: false
]
Column TextColumn@47d1ab77[
  name: (XXXXXXXXXXXXX) Database
  type: 0xa (TEXT)
  number: 2
  length: 100
  variableLength: true
  compressedUnicode: true
  textSortOrder: SortOrder[1033(0)]
]
Column TextColumn@16503677[
  name: (XXXXXXXXXXXXX) Path
  type: 0xa (TEXT)
  number: 3
  length: 100
  variableLength: true
  compressedUnicode: true
  textSortOrder: SortOrder[1033(0)]
]

有人知道如何正确使用UCanAccess吗?在数据库B中有很多到其他.mdb文件的链接

4) UCanAccess错误控制台显示:

    Please, enter the full path to the access file (.mdb or accdb): C:Usersxxx
Desktopxxx.mdb
Loaded Tables:
Loaded Queries:
Loaded Indexes:
Primary Key  on BERECHTIGUNGEN Columns: (INDEX,USERID)
, Primary Key  on DG_FEHLER Columns: (ZAEHLER)
, Primary Key  on FEHLERTABELLE_SICH Columns: (FC,BC,SFBEREICH)
, Primary Key  on FGJG1_FEHLER Columns: (ZAEHLER)
, Primary Key  on GRUNDSCHULEN_LOKAL Columns: (SNR)
, Index Unique  on NRW_STRASSEN Columns: (ID)
, Primary Key  on PWRD Columns: (USERID)
, Primary Key  on SCHULTR─GERART Columns: (SCHULTR─GERART)
, Primary Key  on TABELLENZUMHOST Columns: (TABELLE)
, Primary Key  on TABELLENZUMHOST_BK Columns: (TABELLE)
, Primary Key  on TABELLENZUMHOST_WEITERETABS Columns: (TABELLE,WEITERETABELLE)
, Primary Key  on USERID Columns: (USERID)
, Primary Key  on USERKONV Columns: (USERID)
, Primary Key  on ZFEHLERTABELLE Columns: (FC,BC,SFBEREICH)
net.ucanaccess.jdbc.UcanaccessSQLException
        at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:24
7)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at net.ucanaccess.console.Main.main(Main.java:151)
Caused by: java.lang.NullPointerException
        at net.ucanaccess.converters.UcanaccessTable.getIndexes(UcanaccessTable.
java:74)
        at net.ucanaccess.converters.LoadJet$TablesLoader.loadTableIndexesUK(Loa
dJet.java:794)
        at net.ucanaccess.converters.LoadJet$TablesLoader.createIndexesUK(LoadJe
t.java:835)
        at net.ucanaccess.converters.LoadJet$TablesLoader.loadTables(LoadJet.jav
a:921)
        at net.ucanaccess.converters.LoadJet$TablesLoader.access$3(LoadJet.java:
919)
        at net.ucanaccess.converters.LoadJet.loadDB(LoadJet.java:1311)
        at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:23
6)
        ... 3 more
null
Drücken Sie eine beliebige Taste . . . (en: Press any button to continue . . . )

请使用jaccess:执行此操作

for (String tn : database.getTableNames()) {
       System.out.println(tn);  
        System.out.println(database.getTable(tn));      
}

这可能有助于理解和解决问题。请给我一个反馈。

相关内容

  • 没有找到相关文章