当 Jackcess 连接正常时,UCanAccess 驱动程序在尝试连接 Access 数据库时抛出异常
Posted
技术标签:
【中文标题】当 Jackcess 连接正常时,UCanAccess 驱动程序在尝试连接 Access 数据库时抛出异常【英文标题】:UCanAccess driver throws Exception when trying to connect with Access database while Jackcess connection works fine 【发布时间】:2015-04-01 16:43:02 【问题描述】: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) 以下 Jackcess 示例代码适用于数据库 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:\Users\xxx
\Desktop\xxx.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 . . . )
【问题讨论】:
尝试使用console.bat
或console.sh
(包含在UCanAccess 发行版的根文件夹中)打开麻烦的数据库,看看它是否提供了有关问题的更多详细信息。
我在我的问题中添加了console.bat
输出,但它并不比 java 异常堆栈跟踪更详细:-(
【参考方案1】:
请使用 jackcess 执行此操作:
for (String tn : database.getTableNames())
System.out.println(tn);
System.out.println(database.getTable(tn));
这可能有助于理解和解决。请给我反馈。
【讨论】:
以上是关于当 Jackcess 连接正常时,UCanAccess 驱动程序在尝试连接 Access 数据库时抛出异常的主要内容,如果未能解决你的问题,请参考以下文章
jdbc/Jackcess/Ucanaccess - 无法连接到链接到共享点列表的访问表
使用 iso-8859-1 在 wildfly 中打开 ucanaccess/jackcess 数据库