org.h2.jdbc.JdbcSQLException: Connection is broken: "java.net.BindException: Address already in use: connect: localhost:8092" [90067-196]

1,692 views
Skip to first unread message

Michael Wu

unread,
Feb 20, 2018, 10:15:04 AM2/20/18
to H2 Database
Hi,
I am using H2 In-Memory TCP db server.  I basically follow the example code as listed below:

         final String[] args = new String[] {
            "-tcpAllowOthers",
            "-tcpPort", ""+serverPort
         };
         server = org.h2.tools.Server.createTcpServer(args).start();
         ...
         StringBuilder sb = new StringBuilder();
         sb.append("jdbc:h2:tcp://");
         sb.append(getServerDomainIp());
         sb.append(":");
         sb.append(serverPort);
         sb.append("/mem:cachedb;DB_CLOSE_DELAY=-1");
         h2DbConnectStr = sb.toString();
         ...
         Connection conn = DriverManager.getConnection(h2DbConnectStr);
         // do Insert, Select, Delete, ... db operations

 I use a 10000-iteration loop to test a number of DB operations.  Strangely, the statement DriverManager.getConnection(...) fails to work at some loop iteration due to the following exception:

org.h2.jdbc.JdbcSQLException: Connection is broken: "java.net.BindException: Address already in use: connect: localhost:8092" [90067-196]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
    at org.h2.message.DbException.get(DbException.java:168)
    at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:457)
    at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:334)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:116)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:100)
    at org.h2.Driver.connect(Driver.java:69)
    at java.sql.DriverManager.getConnection(Unknown Source)

Before the exception occurs, the statement works as expected several thousand times.  Any idea about the cause of the problem?

Any help will be appreciated!
Michael Wu

Noel Grandin

unread,
Feb 20, 2018, 2:01:41 PM2/20/18
to h2-da...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages