H2 Database multiple connections

一笑奈何 提交于 2019-11-29 06:39:57
vincenzo iafelice

From H2 documentation:

It is also possible to open the database without file locking; in this case it is up to the application to protect the database files. Failing to do so will result in a corrupted database.

I think that if your application use always the same configuration (shared file database on network folder), you need to create an application layer that manages concurrency

I had the same issue and I've found the solution in the documentation. It can be found at; http://h2database.com/html/features.html#auto_mixed_mode

Multiple processes can access the same database without having to start the server manually. To do that, append ;AUTO_SERVER=TRUE to the database URL. You can use the same database URL independent of whether the database is already open or not. This feature doesn't work with in-memory databases.

// Application 1:
DriverManager.getConnection("jdbc:h2:/data/test;AUTO_SERVER=TRUE");

// Application 2:
DriverManager.getConnection("jdbc:h2:/data/test;AUTO_SERVER=TRUE");
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!