连接到MS Access数据库时出错

时间:2015-06-28 09:58:43

标签: java ms-access

我在Access中有一个数据库。当我尝试使用库UCanAccess连接到它时:

Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
String url = "jdbc:ucanaccess://" + fileSrc;
conn = DriverManager.getConnection(url, user, password);
s = conn.createStatement();
ResultSet rs = s.executeQuery("SELECT * FROM patients");

连接时获取:

conn = DriverManager.getConnection(url, user, password);

此类错误:

WARNING:External file C:\medbase\medbase.mdb does not exist
WARNING:given file does not exist: C:\medbase\medbase.mdb
WARNING:unexpected token: ___________
WARNING:unexpected token: ________
WARNING:unexpected token: _______________________
WARNING:unexpected token: ______________________
WARNING:unexpected token: ____________________
WARNING:unexpected token: ____________
WARNING:unexpected token: __________________
WARNING:unexpected token: ____________________
WARNING:unexpected token: ___________
net.ucanaccess.jdbc.UcanaccessSQLException: unexpected token: _________DEAA914C_823A_11D2_ABBA_525400DB56E6_
    at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:247)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at ru.bigspawn.AccessDatabase.<init>(AccessDatabase.java:20)
    at ru.bigspawn.Main.main(Main.java:40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.sql.SQLSyntaxErrorException: unexpected token: _________DEAA914C_823A_11D2_ABBA_525400DB56E6_
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
    at org.hsqldb.jdbc.JDBCStatement.executeUpdate(Unknown Source)
    at net.ucanaccess.converters.LoadJet.exec(LoadJet.java:1308)
    at net.ucanaccess.converters.LoadJet.access$0(LoadJet.java:1303)
    at net.ucanaccess.converters.LoadJet$TablesLoader.loadForeignKey(LoadJet.java:626)
    at net.ucanaccess.converters.LoadJet$TablesLoader.loadTableFKs(LoadJet.java:819)
    at net.ucanaccess.converters.LoadJet$TablesLoader.createFKs(LoadJet.java:901)
    at net.ucanaccess.converters.LoadJet$TablesLoader.loadTables(LoadJet.java:970)
    at net.ucanaccess.converters.LoadJet$TablesLoader.access$3(LoadJet.java:966)
    at net.ucanaccess.converters.LoadJet.loadDB(LoadJet.java:1361)
    at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:236)
    ... 9 more
Caused by: org.hsqldb.HsqlException: unexpected token: _________DEAA914C_823A_11D2_ABBA_525400DB56E6_
    at org.hsqldb.error.Error.parseError(Unknown Source)
    at org.hsqldb.ParserBase.unexpectedToken(Unknown Source)
    at org.hsqldb.ParserBase.checkIsIrregularCharInIdentifier(Unknown Source)
    at org.hsqldb.ParserDQL.checkIsSchemaObjectName(Unknown Source)
    at org.hsqldb.ParserDQL.readNewSchemaObjectName(Unknown Source)
    at org.hsqldb.ParserDQL.readNewDependentSchemaObjectName(Unknown Source)
    at org.hsqldb.ParserDDL.compileAlterTable(Unknown Source)
    at org.hsqldb.ParserDDL.compileAlter(Unknown Source)
    at org.hsqldb.ParserCommand.compilePart(Unknown Source)
    at org.hsqldb.ParserCommand.compileStatements(Unknown Source)
    at org.hsqldb.Session.executeDirectStatement(Unknown Source)
    at org.hsqldb.Session.execute(Unknown Source)
    ... 20 more

如果我只导出所需的表并连接到它,则没有错误。但我需要使用完整的数据库。

EDITED

我删除了对DB中没有现有文件的引用,但错误仍然存​​在:

WARNING:unexpected token: ___________
WARNING:unexpected token: ________
WARNING:unexpected token: _______________________
WARNING:unexpected token: ______________________
WARNING:unexpected token: ____________________
WARNING:unexpected token: ____________
WARNING:unexpected token: __________________
WARNING:unexpected token: ____________________
WARNING:unexpected token: ___________
net.ucanaccess.jdbc.UcanaccessSQLException: unexpected token: _________DEAA914C_823A_11D2_ABBA_525400DB56E6_
    at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:247)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at ru.bigspawn.AccessDatabase.<init>(AccessDatabase.java:22)
    at ru.bigspawn.Main.main(Main.java:44)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.sql.SQLSyntaxErrorException: unexpected token: _________DEAA914C_823A_11D2_ABBA_525400DB56E6_
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
    at org.hsqldb.jdbc.JDBCStatement.executeUpdate(Unknown Source)
    at net.ucanaccess.converters.LoadJet.exec(LoadJet.java:1308)
    at net.ucanaccess.converters.LoadJet.access$0(LoadJet.java:1303)
    at net.ucanaccess.converters.LoadJet$TablesLoader.loadForeignKey(LoadJet.java:626)
    at net.ucanaccess.converters.LoadJet$TablesLoader.loadTableFKs(LoadJet.java:819)
    at net.ucanaccess.converters.LoadJet$TablesLoader.createFKs(LoadJet.java:901)
    at net.ucanaccess.converters.LoadJet$TablesLoader.loadTables(LoadJet.java:970)
    at net.ucanaccess.converters.LoadJet$TablesLoader.access$3(LoadJet.java:966)
    at net.ucanaccess.converters.LoadJet.loadDB(LoadJet.java:1361)
    at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:236)
    ... 9 more
    Caused by: org.hsqldb.HsqlException: unexpected token: _________DEAA914C_823A_11D2_ABBA_525400DB56E6_
    at org.hsqldb.error.Error.parseError(Unknown Source)
    at org.hsqldb.ParserBase.unexpectedToken(Unknown Source)
    at org.hsqldb.ParserBase.checkIsIrregularCharInIdentifier(Unknown Source)
    at org.hsqldb.ParserDQL.checkIsSchemaObjectName(Unknown Source)
    at org.hsqldb.ParserDQL.readNewSchemaObjectName(Unknown Source)
    at org.hsqldb.ParserDQL.readNewDependentSchemaObjectName(Unknown Source)
    at org.hsqldb.ParserDDL.compileAlterTable(Unknown Source)
    at org.hsqldb.ParserDDL.compileAlter(Unknown Source)
    at org.hsqldb.ParserCommand.compilePart(Unknown Source)
    at org.hsqldb.ParserCommand.compileStatements(Unknown Source)
    at org.hsqldb.Session.executeDirectStatement(Unknown Source)
    at org.hsqldb.Session.execute(Unknown Source)
    ... 20 more

1 个答案:

答案 0 :(得分:1)

这是因为访问中的表和/或FK的名称可能具有西里尔字符或类似的东西。这个问题严格限于ucanaccess 2中的元数据(例如列名或表名),将完全用ucanaccess 3.0.0解决。和支持任何字母的字符。 我正在研究最新的ucanaccess3测试...