使用 DBUnit 将 HSQLDB 导出到 XML 会导致空指针错误

发布于 2024-11-03 10:17:26 字数 4433 浏览 9 评论 0原文

我正在尝试使用 DBUnit 将数据库(HSQLDB)的全部内容导出到 XML,但出现了我无法理解的空指针错误。我正在按照常见问题解答中的示例进行操作:

IDatabaseConnection xmlConnection = new DatabaseConnection(conn);
IDataSet allTables = xmlConnection.createDataSet();
XmlDataSet.write(allTables, new FileOutputStream(DATABASE_PATH + ".xml"));

最后一行出现空指针错误。 conn 和 DATABASE_PATH 不为空,因为它们都经过检查并在程序中稍后使用而没有问题(使用 OpenCSV 将数据库导出到 CSV,它完美且完全符合预期)。

堆栈跟踪如下:

org.dbunit.dataset.DataSetException: java.sql.SQLException: java.lang.NullPointerException java.lang.NullPointerException
    at org.dbunit.database.DatabaseDataSet.initialize(DatabaseDataSet.java:243)
    at org.dbunit.database.DatabaseDataSet.getTableNames(DatabaseDataSet.java:272)
    at org.dbunit.database.DatabaseDataSet.createIterator(DatabaseDataSet.java:258)
    at org.dbunit.dataset.AbstractDataSet.iterator(AbstractDataSet.java:189)
    at org.dbunit.dataset.stream.DataSetProducerAdapter.(DataSetProducerAdapter.java:63)
    at org.dbunit.dataset.xml.XmlDataSetWriter.write(XmlDataSetWriter.java:128)
    at org.dbunit.dataset.xml.XmlDataSet.write(XmlDataSet.java:104)
    at org.dbunit.dataset.xml.XmlDataSet.write(XmlDataSet.java:91)
    at pms.DatabaseExporter.exportToXML(DatabaseExporter.java:181)
    at pms.DatabaseExporter.main(DatabaseExporter.java:301)
Caused by: java.sql.SQLException: java.lang.NullPointerException java.lang.NullPointerException
    at org.hsqldb.jdbc.Util.sqlException(Util.java:224)
    at org.hsqldb.jdbc.JDBCStatement.fetchResult(JDBCStatement.java:1830)
    at org.hsqldb.jdbc.JDBCStatement.executeQuery(JDBCStatement.java:181)
    at org.hsqldb.jdbc.JDBCDatabaseMetaData.execute(JDBCDatabaseMetaData.java:6150)
    at org.hsqldb.jdbc.JDBCDatabaseMetaData.getTables(JDBCDatabaseMetaData.java:3170)
    at org.dbunit.database.DefaultMetadataHandler.getTables(DefaultMetadataHandler.java:137)
    at org.dbunit.database.DatabaseDataSet.initialize(DatabaseDataSet.java:199)
    ... 9 more
Caused by: org.hsqldb.HsqlException: java.lang.NullPointerException
    at org.hsqldb.error.Error.error(Error.java:108)
    at org.hsqldb.result.Result.newErrorResult(Result.java:1069)
    at org.hsqldb.StatementDMQL.execute(StatementDMQL.java:192)
    at org.hsqldb.Session.executeCompiledStatement(Session.java:1315)
    at org.hsqldb.Session.executeDirectStatement(Session.java:1206)
    at org.hsqldb.Session.execute(Session.java:990)
    at org.hsqldb.jdbc.JDBCStatement.fetchResult(JDBCStatement.java:1822)
    ... 14 more
Caused by: java.lang.NullPointerException
    at org.hsqldb.types.CharacterType.compare(CharacterType.java:418)
    at org.hsqldb.index.IndexAVL.compareRowForInsertOrDelete(IndexAVL.java:617)
    at org.hsqldb.index.IndexAVLMemory.insert(IndexAVLMemory.java:214)
    at org.hsqldb.persist.RowStoreAVL.indexRow(RowStoreAVL.java:171)
    at org.hsqldb.persist.RowStoreAVLHybridExtended.indexRow(RowStoreAVLHybridExtended.java:99)
    at org.hsqldb.Table.insertSys(Table.java:2625)
    at org.hsqldb.dbinfo.DatabaseInformationMain.SYSTEM_TABLES(DatabaseInformationMain.java:2353)
    at org.hsqldb.dbinfo.DatabaseInformationMain.generateTable(DatabaseInformationMain.java:348)
    at org.hsqldb.dbinfo.DatabaseInformationFull.generateTable(DatabaseInformationFull.java:379)
    at org.hsqldb.dbinfo.DatabaseInformationMain.setStore(DatabaseInformationMain.java:507)
    at org.hsqldb.persist.PersistentStoreCollectionSession.getStore(PersistentStoreCollectionSession.java:138)
    at org.hsqldb.Table.getRowStore(Table.java:2817)
    at org.hsqldb.RangeVariable$RangeIteratorMain.(RangeVariable.java:939)
    at org.hsqldb.RangeVariable$RangeIteratorMain.(RangeVariable.java:917)
    at org.hsqldb.RangeVariable.getIterator(RangeVariable.java:770)
    at org.hsqldb.QuerySpecification.buildResult(QuerySpecification.java:1293)
    at org.hsqldb.QuerySpecification.getSingleResult(QuerySpecification.java:1245)
    at org.hsqldb.QuerySpecification.getResult(QuerySpecification.java:1235)
    at org.hsqldb.StatementQuery.getResult(StatementQuery.java:66)
    at org.hsqldb.StatementDMQL.execute(StatementDMQL.java:190)
    ... 18 more

我用谷歌搜索,找不到与导出过程中此类错误相关的任何内容。我对 SQL 或 JDBC 没有那么丰富的经验,所以我希望堆栈跟踪中有足够的信息,以便更有知识的人告诉我出了什么问题。如果有其他库更能满足我的需求,我可以毫无问题地切换...我现在唯一需要的是使用 XML 导出/导入,所以我不会将 DBUnit 用于其他任何事情。无论如何,如果有人能告诉我出了什么问题,或者我是否应该使用其他东西,我将非常感激。

I'm trying to export the entire contents of my database, an HSQLDB, to XML using DBUnit, and I'm getting null pointer errors that I can't understand. I'm following the example in the FAQ:

IDatabaseConnection xmlConnection = new DatabaseConnection(conn);
IDataSet allTables = xmlConnection.createDataSet();
XmlDataSet.write(allTables, new FileOutputStream(DATABASE_PATH + ".xml"));

The null pointer error occurs on the last line. conn and DATABASE_PATH aren't null as they're both checked for that and used later in the program without a problem (exporting the database into CSV using OpenCSV, which works perfectly and exactly as expected).

The stacktrace is as follows:

org.dbunit.dataset.DataSetException: java.sql.SQLException: java.lang.NullPointerException java.lang.NullPointerException
    at org.dbunit.database.DatabaseDataSet.initialize(DatabaseDataSet.java:243)
    at org.dbunit.database.DatabaseDataSet.getTableNames(DatabaseDataSet.java:272)
    at org.dbunit.database.DatabaseDataSet.createIterator(DatabaseDataSet.java:258)
    at org.dbunit.dataset.AbstractDataSet.iterator(AbstractDataSet.java:189)
    at org.dbunit.dataset.stream.DataSetProducerAdapter.(DataSetProducerAdapter.java:63)
    at org.dbunit.dataset.xml.XmlDataSetWriter.write(XmlDataSetWriter.java:128)
    at org.dbunit.dataset.xml.XmlDataSet.write(XmlDataSet.java:104)
    at org.dbunit.dataset.xml.XmlDataSet.write(XmlDataSet.java:91)
    at pms.DatabaseExporter.exportToXML(DatabaseExporter.java:181)
    at pms.DatabaseExporter.main(DatabaseExporter.java:301)
Caused by: java.sql.SQLException: java.lang.NullPointerException java.lang.NullPointerException
    at org.hsqldb.jdbc.Util.sqlException(Util.java:224)
    at org.hsqldb.jdbc.JDBCStatement.fetchResult(JDBCStatement.java:1830)
    at org.hsqldb.jdbc.JDBCStatement.executeQuery(JDBCStatement.java:181)
    at org.hsqldb.jdbc.JDBCDatabaseMetaData.execute(JDBCDatabaseMetaData.java:6150)
    at org.hsqldb.jdbc.JDBCDatabaseMetaData.getTables(JDBCDatabaseMetaData.java:3170)
    at org.dbunit.database.DefaultMetadataHandler.getTables(DefaultMetadataHandler.java:137)
    at org.dbunit.database.DatabaseDataSet.initialize(DatabaseDataSet.java:199)
    ... 9 more
Caused by: org.hsqldb.HsqlException: java.lang.NullPointerException
    at org.hsqldb.error.Error.error(Error.java:108)
    at org.hsqldb.result.Result.newErrorResult(Result.java:1069)
    at org.hsqldb.StatementDMQL.execute(StatementDMQL.java:192)
    at org.hsqldb.Session.executeCompiledStatement(Session.java:1315)
    at org.hsqldb.Session.executeDirectStatement(Session.java:1206)
    at org.hsqldb.Session.execute(Session.java:990)
    at org.hsqldb.jdbc.JDBCStatement.fetchResult(JDBCStatement.java:1822)
    ... 14 more
Caused by: java.lang.NullPointerException
    at org.hsqldb.types.CharacterType.compare(CharacterType.java:418)
    at org.hsqldb.index.IndexAVL.compareRowForInsertOrDelete(IndexAVL.java:617)
    at org.hsqldb.index.IndexAVLMemory.insert(IndexAVLMemory.java:214)
    at org.hsqldb.persist.RowStoreAVL.indexRow(RowStoreAVL.java:171)
    at org.hsqldb.persist.RowStoreAVLHybridExtended.indexRow(RowStoreAVLHybridExtended.java:99)
    at org.hsqldb.Table.insertSys(Table.java:2625)
    at org.hsqldb.dbinfo.DatabaseInformationMain.SYSTEM_TABLES(DatabaseInformationMain.java:2353)
    at org.hsqldb.dbinfo.DatabaseInformationMain.generateTable(DatabaseInformationMain.java:348)
    at org.hsqldb.dbinfo.DatabaseInformationFull.generateTable(DatabaseInformationFull.java:379)
    at org.hsqldb.dbinfo.DatabaseInformationMain.setStore(DatabaseInformationMain.java:507)
    at org.hsqldb.persist.PersistentStoreCollectionSession.getStore(PersistentStoreCollectionSession.java:138)
    at org.hsqldb.Table.getRowStore(Table.java:2817)
    at org.hsqldb.RangeVariable$RangeIteratorMain.(RangeVariable.java:939)
    at org.hsqldb.RangeVariable$RangeIteratorMain.(RangeVariable.java:917)
    at org.hsqldb.RangeVariable.getIterator(RangeVariable.java:770)
    at org.hsqldb.QuerySpecification.buildResult(QuerySpecification.java:1293)
    at org.hsqldb.QuerySpecification.getSingleResult(QuerySpecification.java:1245)
    at org.hsqldb.QuerySpecification.getResult(QuerySpecification.java:1235)
    at org.hsqldb.StatementQuery.getResult(StatementQuery.java:66)
    at org.hsqldb.StatementDMQL.execute(StatementDMQL.java:190)
    ... 18 more

I've googled and couldn't find anything relating to this kind of error during export. I'm not that experienced with SQL or JDBC so I'm hoping there's enough info in the stack trace for someone more knowledgeable to tell me what's going wrong. If there's some other library that would be better for my needs, I have no problem switching... The only thing I need is export/import with XML right now, so I'm not using DBUnit for anything else. Anyway if anybody can tell me what's going on wrong or if I ought to be using something else I'd really appreciate it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国际总奸 2024-11-10 10:17:26

这是特定版本的 HSQLDB 系统表创建中的错误,最近被发现并已更正。您可以尝试 http://hsqldb.org/support/ 中更新的 HSQLDB jar

This is an error in the particular version of HSQLDB's system table creation, which was spotted and corrected recently. You can try the updated HSQLDB jar from http://hsqldb.org/support/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文