简体   繁体   English

并发嵌入式Java数据库,可简化应用程序

[英]Concurrency embedded Java Database for simple Application

I am trying to build a simple GUI in which you can write some Integers. 我正在尝试构建一个简单的GUI,您可以在其中编写一些Integer。 These Integers are supposed to be written into a Database, which I am looking for. 这些整数应该被写到我正在寻找的数据库中。

So far so good. 到现在为止还挺好。 The data in the Database should then be used for another stand-alone application, which already exists. 然后,应该将数据库中的数据用于另一个已经存在的独立应用程序。

I tried it with SQLite already but I received a lot of "Database locked" Errors. 我已经使用SQLite尝试过,但是收到很多“数据库锁定”错误。 I searched Google. 我搜索了Google。 The key answer I often read about was to switch to a database which supports concurrent processes. 我经常读到的关键答案是切换到支持并发进程的数据库。

I went further on and had a look at H2 and HSQLDB. 我进一步研究了H2和HSQLDB。 Both of them seem to be legit but much more complicated. 他们两个似乎都是合法的,但要复杂得多。

So I wonder: 所以我想知道:

I would like to have the GUI to be portable in a .jar file (or a folder only) combined with the Database, so when I switch computers I do not have to install the DB in a certain folder like the home-directory or something. 我希望GUI可以在与数据库结合的.jar文件(或仅文件夹)中移植,因此,当我切换计算机时,不必将DB安装在某个文件夹(如主目录或其他目录)中。 With SQLite all you do is this: 使用SQLite,您要做的就是:

Connection con = DriverManager.getConnection("jdbc:sqlite:test.db");

As you can see, no Path-infortmation is necessary. 如您所见,不需要路径激励。 How can I do this with H2 or HSQLDB? 我该如何使用H2或HSQLDB?

I am really looking forward to your suggestions. 我真的很期待您的建议。 But only open source please. 但是请只开源。

Kindest regards and thank you very much! 亲切的问候,非常感谢!

Stefan 斯特凡

处理嵌入式数据库文件的创建应该不是什么大问题-但是,如果您真的不喜欢SQLite的话:它应该能够很好地处理并发性以进行基本使用-“数据库锁定”听起来更像是应用程序级问题

With H2 and HSQLDB you can do the same. 使用H2和HSQLDB,您可以执行相同的操作。

With H2, a database URL of the form jdbc:h2:test will create a file called test.h2.db in the current working directory of your application. 使用H2,形式为jdbc:h2:test的数据库URL将在应用程序的当前工作目录中创建一个名为test.h2.db的文件。 If this is what you want, then that's fine. 如果这是您想要的,那很好。 Please note I usually don't suggest to do that, because many people run into the problem that they sometimes start the application in a different directory (which will then create a new database). 请注意,我通常不建议这样做,因为很多人遇到这样的问题,他们有时会在不同的目录中启动应用程序(然后将创建一个新的数据库)。 Because of that, I suggest to use jdbc:h2:~/test , which means the database file is stored relative to the current user home directory. 因此,我建议使用jdbc:h2:~/test ,这意味着数据库文件是相对于当前用户主目录存储的。

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

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