Numerous H2 Database Connections

I have the following problem: Two application instances on two different systems must share a small database. The main problem is that both systems can only exchange data through a network folder. I have no way to configure the database server anywhere.

Is it possible to place the H2 database in a network folder and allow both instances to connect to the database (also at the same time)?

I could connect with both instances to db using native mode if I disable file locking, right? Instances can perform READ or INSERT operations on db. Can I risk data corruption using multiple concurrent inline connections?

+7
source share
2 answers

From the H2 documentation :

You can also open the database without locking files; This is because the application protects database files. Otherwise, it will damage the database.

I think that if your application always uses the same configuration (shared file database in a network folder), you need to create an application layer that controls concurrency

+2
source

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

Several processes can access the same database without having to start the server manually. To do this, add AUTO_SERVER = TRUE to the database URL. You can use the same database URL, whether the database is open or not. This function does not 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"); 
+22
source

All Articles