Java application with H2 database

418 views
Skip to first unread message

Luigi Galati

unread,
Jul 1, 2016, 9:24:17 AM7/1/16
to H2 Database
Hi I have a java local desktop application that use a shared H2 database (on the LAN).
I use AUTO_SERVER=TRUE options, so the auto_server mode.
But I don't understand if this mode works only if the different applications run on the same machine. I have this problem when an user tries to use the program when another are using it:

org.h2.jdbc.JdbcSQLException: Connection is broken: "java.net.ConnectException: Connection refused: connect: 127.0.1.1:44256" [90067-176]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:344)
    at org.h2.message.DbException.get(DbException.java:167)
    at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:434)
    at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:344)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:107)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:91)
    at org.h2.Driver.connect(Driver.java:74)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at gestionalelauncher.db.DbManager.getConnection(DbManager.java:47)
    at gestionalelauncher.db.DbManager.getLastDateOfBackup(DbManager.java:67)
    at gestionalelauncher.GestionaleLauncher.start(GestionaleLauncher.java:75)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused: connect


Can you help me with this problem? I have to use a server mode? And then how I can do with concurrency?

Luigi Galati

unread,
Jul 1, 2016, 11:56:14 AM7/1/16
to H2 Database
Update:
Seems that the first application connected to the database write correctly the lock file with server (auto-server) informations but when the second application have to use them the server doesn't start....

Noel Grandin

unread,
Jul 9, 2016, 8:22:14 AM7/9/16
to h2-da...@googlegroups.com
What kind of share is it? Windows shares are known to be flakey in this regard.​

Luigi Galati

unread,
Jul 11, 2016, 3:29:44 AM7/11/16
to H2 Database
Sorry but I didn't understand the question. :)
I have a JavaFX desktop application that uses a shared H2 database. I can have more users connected to the same database at the same time.
Mixed mode (AUTO_SERVER=TRUE;) doesn't work always, but most of times the client receives the error above.
I didn't read anywhere in H2 documentation that this feature (Mixed Mode) works only with Linux/OS operating systems...

Noel Grandin

unread,
Jul 12, 2016, 4:10:53 AM7/12/16
to h2-da...@googlegroups.com
Ah sorry, I misread you original post.

Something is weird in your network configuration - H2 is not picking up the name of the machine that is currently
running the database correctly.
I would suggest checking your network and DNS settings.

Luigi Galati

unread,
Jul 12, 2016, 4:21:05 AM7/12/16
to h2-da...@googlegroups.com
Ok, I'll check it. Thank you! :)

--
You received this message because you are subscribed to a topic in the Google Groups "H2 Database" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/h2-database/2Yg2uYb4O7w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to h2-database...@googlegroups.com.
To post to this group, send email to h2-da...@googlegroups.com.
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Paul Erdos

unread,
Jul 12, 2016, 6:16:05 AM7/12/16
to H2 Database
I didn't read anywhere in H2 documentation that this feature (Mixed Mode) works only with Linux/OS operating systems...

Indeed it's not written anywhere, we use H2 database with multiple Windows PC sharing a network hard disk where the database file is and the first computer to launch the application accesses the file on the network drive while others connect via TCP automatically.


But I don't understand if this mode works only if the different applications run on the same machine

 this mode works for computers in different machines across a LAN network, ottherwise it would be quite useless.

If you could post the startup string for the database maybe I can have a look at it.

Luigi Galati

unread,
Jul 12, 2016, 6:30:08 AM7/12/16
to H2 Database
Hi, the db url is a dinamically string like this:
String urlDb = "jdbc:h2:"+ dbFilePath+";IFEXISTS=TRUE;AUTO_SERVER=TRUE;"
where dbFilePath is a absolute path of db file, for example:
Z:\FOO\BAR\PATH\h2Db
the db's path is chosen by FileChooser.

Reply all
Reply to author
Forward
0 new messages