尝试获取.accdb数据库(2007-2016格式)中所有表的列表。似乎无法找到MSysObjects表。使用UCanAccess
sql = "SELECT Name FROM MSysObjects WHERE Type = 1 AND Flags = 0";
ResultSet rs = queryChem(sql);
public static ResultSet queryChem(String sql) throws SQLException {
Statement sChem = connChem.createStatement();
ResultSet rsChem = sChem.executeQuery(sql);
return rsChem;
}
private static void connectChem() {
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
System.out.println("Driver loaded");
String url = "jdbc:ucanaccess://chemdb.accdb";
connChem = DriverManager.getConnection(url);
System.out.println("Database Connected - CHEMS");
} catch (Exception ex) {
System.out.println("Error");
}
}
net.ucanaccess.jdbc.UcanaccessSQLException:UCAExc ::: 3.0.6用户缺少未找到的权限或对象:MSYSOBJECTS 在net.ucanaccess.jdbc.UcanaccessStatement.executeQuery(UcanaccessStatement.java:211)
答案 0 :(得分:2)
您不需要点击[MSysObjects]表。您可以通过DatabaseMetaData#getTables
方法获取表格列表,例如
try (ResultSet rsMD = connChem.getMetaData().getTables(null, null, null, null)) {
while (rsMD.next()) {
String tblName = rsMD.getString("TABLE_NAME");
System.out.println(tblName);
}
}