java 如何允许多个用户同时连接到我的 H2 数据库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26743992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 10:31:37  来源:igfitidea点击:

How do I allow multiple users to connect to my H2 database simultaneously?

javasqldatabaseh2

提问by Ryan

I am using H2 for database management, and this is what I would like to do:

我正在使用 H2 进行数据库管理,这就是我想要做的:

I would like to allow multiple users to access a database at the same time. I've read a bit about "MULTI_THREADED=TRUE", "LOCK_FILE=NO", and "AUTO_SERVER=TRUE". I've also read that "LOCK_FILE=NO" can be dangerous, because it can corrupt the database. I definitely would not want this, so I'm assuming that is a bad way to go. I've also tried to close the connection immediately after a record is accessed, whether it is being read from or written to. So far, nothing seems to work. The application is not allowing me to read from or write to the database if the database has been connected to in a separate instance of the application (ex: on another computer). Once I completely close the application on one computer, I am able to access the database records.

我想允许多个用户同时访问一个数据库。我读过一些关于“MULTI_THREADED=TRUE”、“LOCK_FILE=NO”和“AUTO_SERVER=TRUE”的内容。我还读到“LOCK_FILE=NO”可能很危险,因为它会损坏数据库。我绝对不想要这个,所以我认为这是一个糟糕的方法。我还尝试在访问记录后立即关闭连接,无论是读取还是写入。到目前为止,似乎没有任何效果。如果数据库已连接到应用程序的单独实例(例如:在另一台计算机上),则应用程序不允许我读取或写入数据库。一旦我在一台计算机上完全关闭应用程序,我就可以访问数据库记录。

How do I allow multiple users to connect to the H2 database at the same time without compromising the safety of the database?

如何在不影响数据库安全的情况下,允许多个用户同时连接到H2数据库?

回答by Lolo

It looks like you are using H2 in embedded mode, which only allows one database connection at a time. See connection modesin the documentation for details.

看起来您在嵌入式模式下使用 H2,它一次只允许一个数据库连接。有关详细信息,请参阅文档中的连接方式

If you need support for multiple connections, including from multiple application instances, then you need to start H2 in server modeinstead and use the appropriate connection URLsfor this mode.

如果您需要支持多个连接,包括来自多个应用程序实例,那么您需要在服务器模式下启动 H2,并为此模式使用适当的连接 URL

回答by Hymankobec

AUTO_SERVER=TRUEallows multiple connections mode.

AUTO_SERVER=TRUE允许多连接模式。