使用嵌入式 Java 数据库处理来自 Web 的 CSV 文件

发布于 2024-07-10 19:37:03 字数 593 浏览 5 评论 0原文

简短版本:假设我不想长时间保留数据,如何在 HSQLDB 中以编程方式创建数据库并将一些 CSV 数据加载到其中? 我的架构将与文件完全匹配,并且文件确实有足够的列名称。

这是一个无人值守的过程。

详细信息:

我需要对通过网络下载的三个 CSV 文件应用一些简单的 SQL 技术,然后创建一些 DTO,然后我可以将它们与一些现有代码一起使用来进一步处理它们,并通过 REST 保存它们。 我真的不想搞乱数据库,但 CSV 文件是通过外键链接的,所以我正在考虑使用内存嵌入式数据库来完成这项工作,然后扔掉所有这些。

我想到了一个像这样工作的命令行应用程序:

  1. 在 HSQLDB 中创建一个新的数据库。
  2. 三分之三启动三个 HTTP GET 使用 Apache HttpClient 的线程。
  3. 将 CSV 导入三个 HSQLDB 内存表。
  4. 运行一些 SQL。
  5. 将结果解析到我现有的 DTO。
  6. 等等...

我可以使用对第 1 项和第 3 项有帮助的代码和实用程序的指针。我还应该考虑 HSQLDB 的替代方案吗?

Short version: assuming I don't want to keep the data for long, how do I create a database programmaticly in HSQLDB and load some CSV data into it to? My schema will match the files exactly and the files do have adequate column names.

This is an unattended process.

Details:

I need to apply some simple SQL techniques to three CSV files downloaded via the web, then create some DTOs which I can then use with some existing code to process them some more, and save them via REST. I don't really want to mess around with databases but the CSV files are linked by foreign keys, so I was thinking of using an in-memory embedded database to do the work, then throw the whole lot away.

I had in mind a command line app working like this:

  1. Create a fresh database in HSQLDB.
  2. Start three HTTP GETs in three
    threads using Apache HttpClient.
  3. Import the CSVs into three HSQLDB
    MEMORY tables.
  4. Run some SQL.
  5. Parse the results into my existing
    DTOs.
  6. Etc...

I could use pointers to code and utilities helpful for items 1, and 3. Also is there an alternative to HSQLDB I should consider?

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

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

发布评论

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

评论(2

谁与争疯 2024-07-17 19:37:03

要使用的命令行应用程序是 HSQLDB 附带的 SqlTool 实用程序 jar。 您的过程可以按如下方式完成:

  1. 创建一个新的 HSQLDB 内存数据库(只需连接到内存数据库)。
  2. 使用 Apache HttpClient 启动三个 HTTP GET 以获取 CSV 文件。
  3. 创建三个 HSQLDB TEXT 表并将这些表的 SOURCE 设置为 CSV
  4. 运行一些 SQL。 将结果解析到现有的 DTO 中。

当提出问题时,不可能在纯内存表中创建 TEXT 表。 现在 HSQLDB 2.x 版本完全支持它。

The command line app to use is the SqlTool utility jar that is supplied with HSQLDB. Your procedure can be completed as follows:

  1. Create a fresh HSQLDB in-memory database (just connect to the in-memory database).
  2. Start three HTTP GETs using Apache HttpClient to get the CSV files.
  3. Create three HSQLDB TEXT tables and set the SOURCE of these tables to the CSVs
  4. Run some SQL. Parse the results into your existing DTOs.

Creating TEXT tables in pure in-memory tables was not possible when the question was asked. It is now fully supported in HSQLDB 2.x versions.

一世旳自豪 2024-07-17 19:37:03

检查opencvs。 它可以帮助您解析 CSV 文件。

Check opencvs. It helps you to parse CSV files.

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