2

I'm following this question. I am getting error after opening the h2 database console, i enter database name but it is showing database not found errir

I have the same issue. The user @joelittlejohn provided the answer and the answer is to add the flag -ifNotExists. But I don't know where to add the flag. I can't add comment because it need 50 points I'm a new I don't have 50 points. So I have to ask here.

I'm following a tutorial on using H2 with spring boot. where should I add the -ifNotExists flag to h2 start command? Is it added to the application.properties file or somewhere else?

I also tried the independent version . How to add the flag? I added to h2.bat but this is not working. Where should I add it?

@java -cp -ifNotExists "h2-1.4.199.jar;%H2DRIVERS%;%CLASSPATH%" org.h2.tools.Console%*
@if errorlevel 1 pause
Haz Wof
  • 163
  • 2
  • 11

1 Answers1

3

-ifNotExists is a command-line argument for the Server tool. The option is not supported by Console. You should change the bat file like this:

@java -cp "h2-1.4.199.jar;%H2DRIVERS%;%CLASSPATH%" org.h2.tools.Server -ifNotExists 

To start H2 in server mode with Spring Boot see this post How to enable H2 Database Server Mode in Spring Boot. You may pass the option like this:

public Server h2Server() throws SQLException {
        return Server.createTcpServer("-ifNotExists", "-tcpAllowOthers", ...);
}

You could still run H2 in embedded mode and in this case the database should be created by default.

b0gusb
  • 4,283
  • 2
  • 14
  • 33
  • Thanks, Is this should be add it the h2.bat? And how to add the flag when I use h2 in a Spring Boot project? Is it added to the application.properties file or somewhere else? – Haz Wof May 29 '19 at 12:12