简体   繁体   English

JDBC-从OpenOffice数据库获取所有表名

[英]JDBC - Get all Table names from OpenOffice Database

long time lurker, first question time. 长时间潜伏,第一个提问时间。

I tried searching for how to get all of the tables from a database created with OpenOffice using JDBC, and while I found answers that work for others, they do not work for me. 我尝试搜索如何从使用JDBC使用OpenOffice创建的数据库中获取所有表,尽管我发现了对其他人有用的答案,但对我却不起作用。 The code itself actually returns something, but it returns something completely unexpected. 代码本身实际上返回了一些内容,但返回的内容完全出乎意料。

My code: 我的代码:

    try {
        DatabaseMetaData md = conn.getMetaData();
        rs = md.getTables(null, null, "%", null);

        while (rs.next()) {
            tableNames.add(rs.getString(3));
            System.out.println(rs.getString(3));
        }

    }
    catch (Exception e) {
        System.out.println("error in sendConnection()");
    }

And the output: 并输出:

SYSTEM_ALIASES
SYSTEM_ALLTYPEINFO
SYSTEM_AUTHORIZATIONS
SYSTEM_BESTROWIDENTIFIER
SYSTEM_CACHEINFO
SYSTEM_CATALOGS
SYSTEM_CHECK_COLUMN_USAGE
SYSTEM_CHECK_CONSTRAINTS
SYSTEM_CHECK_ROUTINE_USAGE
SYSTEM_CHECK_TABLE_USAGE
SYSTEM_CLASSPRIVILEGES
SYSTEM_COLLATIONS
SYSTEM_COLUMNPRIVILEGES
SYSTEM_COLUMNS
SYSTEM_CROSSREFERENCE
SYSTEM_INDEXINFO
SYSTEM_PRIMARYKEYS
SYSTEM_PROCEDURECOLUMNS
SYSTEM_PROCEDURES
SYSTEM_PROPERTIES
SYSTEM_ROLE_AUTHORIZATION_DESCRIPTORS
SYSTEM_SCHEMAS
SYSTEM_SCHEMATA
SYSTEM_SEQUENCES
SYSTEM_SESSIONINFO
SYSTEM_SESSIONS
SYSTEM_SUPERTABLES
SYSTEM_SUPERTYPES
SYSTEM_TABLEPRIVILEGES
SYSTEM_TABLES
SYSTEM_TABLETYPES
SYSTEM_TABLE_CONSTRAINTS
SYSTEM_TEXTTABLES
SYSTEM_TRIGGERCOLUMNS
SYSTEM_TRIGGERS
SYSTEM_TYPEINFO
SYSTEM_UDTATTRIBUTES
SYSTEM_UDTS
SYSTEM_USAGE_PRIVILEGES
SYSTEM_USERS
SYSTEM_VERSIONCOLUMNS
SYSTEM_VIEWS
SYSTEM_VIEW_COLUMN_USAGE
SYSTEM_VIEW_ROUTINE_USAGE
SYSTEM_VIEW_TABLE_USAGE

What is being returned, and how can I work around or resolve this? 返回了什么,我该如何解决或解决此问题? Thank you in advance! 先感谢您!

Edit: The Databases created buh OpenOffice appear to be Embedded Databases by default. 编辑:默认情况下,由OpenOffice创建的数据库似乎是嵌入式数据库。 This may be causing the problem. 这可能是导致问题的原因。 Going to try and convert it to something else and see what happens. 尝试将其转换为其他内容,然后看看会发生什么。

I found a way to fix this, in case others come across this problem as well. 我发现了一种解决此问题的方法,以防其他人也遇到此问题。 The problem was OpenOffice was saving the database as a base file, with hsqldb under it. 问题是OpenOffice将数据库另存为基本文件,并在其下包含hsqldb。 You need to make it just a regular hsqldb. 您只需使其成为常规的hsqldb。

I used both of these links as resources: 我将这两个链接用作资源:

http://programmaremobile.blogspot.com/2009/01/java-and-openoffice-base-db-through.html http://programmaremobile.blogspot.com/2009/01/java-and-openoffice-base-db-through.html

https://forum.openoffice.org/en/forum/viewtopic.php?f=83&t=65980 https://forum.openoffice.org/en/forum/viewtopic.php?f=83&t=65980

In short, you need to extract the .odb file, go into the directories and find the database directory holding 4 other files. 简而言之,您需要解压缩.odb文件,进入目录并找到包含其他4个文件的数据库目录。 Add a prefix to them and then access it like normal. 给它们添加前缀,然后像平常一样访问它。

I am still getting the monstrosity of the SYSTEM_* tables, but now I am actually getting the tables I want as well. 我仍然在获取SYSTEM_ *表的怪异之处,但是现在我实际上也在获取我想要的表。 From there I think I can figure out how to just get those random tables. 从那里我想我可以弄清楚如何获取那些随机表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM