UCanAccess 无法读取带有“... FROM TableName IN 'FileSpec'”的查询
Posted
技术标签:
【中文标题】UCanAccess 无法读取带有“... FROM TableName IN \'FileSpec\'”的查询【英文标题】:UCanAccess cannot read query with "... FROM TableName IN 'FileSpec'"UCanAccess 无法读取带有“... FROM TableName IN 'FileSpec'”的查询 【发布时间】:2016-10-04 11:48:06 【问题描述】:我需要使用 UCanAccess 从 MS Access 的视图中读取数据。我在 C:\DataBases
中有两个数据库-
DBa(包含表:TableOfDBa)。
-
DBb(包含 QueryLinkTable view of TableOfDBa)。
QueryLinkTable 是:
SELECT * FROM TableOfDBa IN 'C:\DataBases\DBa.mdb';
代码是:
package es.fips;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class ReadData
private static String pathDB = "//C:/DataBases/DBb.mdb";
public static void main(String[] args)
Connection conn = getConnectionOn();
String nameView = "QueryLinKTable";
if(conn != null)
System.out.println("Connected Data Base =D");
if(thereAreViews(conn))
// This can not read the query from view
printView(conn, nameView);
printView(conn, nameView);
public static Connection getConnectionOn()
Connection myConnection = null;
try
myConnection = DriverManager.getConnection("jdbc:ucanaccess:" + pathDB);
return myConnection;
catch (SQLException e)
System.out.println("Error connecting");
return null;
public static boolean thereAreViews(Connection oneConn)
try
DatabaseMetaData metaDB = oneConn.getMetaData();
String[] types = "VIEW" ;
int numViews = 0;
ResultSet rs = metaDB.getTables(null, null, null, types);
while (rs.next())
System.out.println("View " + (numViews + 1) + ": " + rs.getString(3));
numViews++;
if (numViews > 0)
return true;
else
System.out.println("There are no views");
return false;
catch (SQLException e)
e.printStackTrace();
return false;
public static void printView(Connection oneConn, String nameView)
try
Statement st = oneConn.createStatement();
String query = "SELECT * FROM " + nameView;
ResultSet rs = st.executeQuery(query);
while (rs.next())
System.out.println("Read! =D");
catch (SQLException e)
e.printStackTrace();
错误是:
Connected Data Base =D
There are no views
net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.6 usuario no tiene privilegios suficientes o objeto no encontrado: QUERYLINKTABLE
at net.ucanaccess.jdbc.UcanaccessStatement.executeQuery(UcanaccessStatement.java:211)
at es.fips.ReadData.printView(ReadData.java:69)
at es.fips.ReadData.main(ReadData.java:25)
Caused by: java.sql.SQLSyntaxErrorException: usuario no tiene privilegios suficientes o objeto no encontrado: QUERYLINKTABLE
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.executeQuery(Unknown Source)
at net.ucanaccess.jdbc.UcanaccessStatement.executeQuery(UcanaccessStatement.java:208)
... 2 more
Caused by: org.hsqldb.HsqlException: usuario no tiene privilegios suficientes o objeto no encontrado: QUERYLINKTABLE
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.ParserDQL.readTableName(Unknown Source)
at org.hsqldb.ParserDQL.readTableOrSubquery(Unknown Source)
at org.hsqldb.ParserDQL.XreadTableReference(Unknown Source)
at org.hsqldb.ParserDQL.XreadFromClause(Unknown Source)
at org.hsqldb.ParserDQL.XreadTableExpression(Unknown Source)
at org.hsqldb.ParserDQL.XreadQuerySpecification(Unknown Source)
at org.hsqldb.ParserDQL.XreadSimpleTable(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryPrimary(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryTerm(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryExpressionBody(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryExpression(Unknown Source)
at org.hsqldb.ParserDQL.compileCursorSpecification(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)
... 5 more
如果您知道任何解决方案,我将不胜感激
【问题讨论】:
【参考方案1】:目前(从 3.0.6 版开始),UCanAccess 不支持语法
SELECT * FROM TableName IN 'C:\Path\To\DbFile.mdb'
如果您尝试使用 UCanAccess 控制台(console.bat 或 console.sh)打开 DBb.mdb,您将看到
Error occured at the first loading attempt of QueryLinKTable
Converted view was :CREATE VIEW QUERYLINKTABLE AS SELECT *
FROM TableOfDBa IN 'C:\Users\Public\test\DBa.mdb'
Error message was :unexpected token: IN : line: 2
在您的情况下,您需要在 DBb.mdb 中创建一个名为 [TableOfDBa] 的实际链接表,该表指向 DBa.mdb 中的表,然后更改 DBb 中的视图(保存的查询) .mdb 到
SELECT * FROM TableOfDBa
【讨论】:
以上是关于UCanAccess 无法读取带有“... FROM TableName IN 'FileSpec'”的查询的主要内容,如果未能解决你的问题,请参考以下文章
jdbc/Jackcess/Ucanaccess - 无法连接到链接到共享点列表的访问表