0

I want to start a h2 database server and connect multiple java applications to it. In order to do this I started a h2 server (version 1.4.196) with the below command

java -cp h2-1.4.196.jar org.h2.tools.Server -tcp -web

I see the below output of the above command

TCP server running at tcp://10.234.4.136:9092 (only local connections)
Web Console server running at http://10.234.4.136:8082 (only local connections)

Then I start a spring boot application with the below application.properties

server.port=9090
spring.datasource.url=jdbc:h2:tcp://10.234.4.136:9092/~/AZ
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=create

The java code is

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        new SpringApplicationBuilder(Application.class)
                .properties("spring.config.name:application")
                .build()
                .run(args);
    }

}

The spring boot (version 1.3.6) application starts but gets stuck at schema export step with the below logs

2018-03-17 20:38:46.290  WARN 17260 --- [ost-startStop-1] o.h.e.jdbc.internal.JdbcServicesImpl     : HHH000341: Could not obtain connection metadata : Connection is broken: "unexpected status 16843008" [90067-192]
2018-03-17 20:38:46.291  INFO 17260 --- [ost-startStop-1] o.h.e.jdbc.internal.LobCreatorBuilder    : HHH000422: Disabling contextual LOB creation as connection was null
2018-03-17 20:38:46.348  INFO 17260 --- [ost-startStop-1] o.h.h.i.ast.ASTQueryTranslatorFactory    : HHH000397: Using ASTQueryTranslatorFactory
2018-03-17 20:38:46.496  INFO 17260 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export

I want to start multiple java applications that connect to the same h2 database server but the first one gets stuck as stated above.

Andy Dufresne
  • 6,022
  • 7
  • 63
  • 113
  • I fail to understand how this is a duplicate of the other question. I am neither starting the server with the same config options that the other question states nor does the answer specified their resolve the problem I state above. Kindly share more details before marking it as a duplicate. – Andy Dufresne Mar 19 '18 at 03:53

1 Answers1

-2

Try replacing the IP in spring.datasource.url with 'localhost'. Otherwise, start the h2 server with -tcpAllowOthers options.

Also answered here: How to run H2 database in server mode?

GbGbGbGbEB
  • 56
  • 1
  • 6
  • Replacing the program with the ip address didn't help. Given that I am trying to connect different local applications to the same database, does that mean that I need to first start the server in mixed mode? If so, what are the connection urls to start the server and for other applications to connect? – Andy Dufresne Mar 19 '18 at 03:51