当前位置: 首页 > 知识库问答 >
问题:

连接到MS Access数据库时出错

颛孙炜
2023-03-14

我有一个数据库。当我尝试使用库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

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

编辑

我删除了对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个答案

羊禄
2023-03-14

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

 类似资料:
  • 问题内容: 如何使用SQLAlchemy连接到MS Access?在他们的网站上,它说连接字符串是access + pyodbc。这是否意味着我需要连接pyodbc?由于我是新手,请保持温柔。 问题答案: 从理论上讲,这将通过create_engine(“ access:/// some_odbc_dsn”)进行,但是自从SQLAlchemy 0.5以来,Access后端就一直没有使用过,并且尚不

  • 我是php的初学者,对于一个项目,我想把我和数据库连接起来,但问题是: 我需要4个变量: 当我这样做时: 有两个错误: 警告:mysqli::mysqli():php_network_getaddress:getaddrinfo失败:第21行/home/ubuntu/workspace/index.php中的名称或服务未知 而且 警告:mysqli::mysqli():(HY000/2002):p

  • 查询数据库时出错。原因:org.springframework.JDBC.canNotgetJDBCConnectionException:未能获得JDBC连接;嵌套异常是java.sql.sqlexception:对文件“d:companydbprodatafile.fdb”进行“createFile(open)”操作时发生I/O错误;试图打开文件时出错;[SQLSTATE:08001,ISC错

  • 我目前正试图找到一个替代我的android应用程序后端。目前,我使用php servlets查询Mysql数据库。数据库(Mysql)托管在我学院的一台计算机上,所以我不能更改任何配置,因为我不是管理员。我只能编辑自己的表。 我试图使用以下代码创建一个java RESTful服务器:

  • 有人能帮帮我吗?在网上找不到有关此问题的任何内容。

  • 如果有人能在这里帮忙,我真的很高兴。