In an embedded H2 database, how to prevent it from creating a database, by means of the connection URL?

StackOverflow https://stackoverflow.com/questions/23205445

  •  07-07-2023
  •  | 
  •  

Question

I have a third party tool that I want to detect right away that the database is missing, instead of creating the empty database. I cannot change the tool itself, but only configure it. Not getting any error during database connection gives the application the false impression that the database is there, with all necessary tables. So the application will fail only when it does not find the tables.

I want an SQLException to be thrown as soon as the application tries to connect to a database that does not exist. For instance, if the connection URL is jdbc:h2:/x/y and the file /x/y.h2.db does not exist.

Is there a way, using the connection URL, to specify that the database should not be created? In other words, is there a way to tell the H2 driver to treat the absence of data files as an error that should be reported?

Is there anything like this? => jdbc:h2:/x/y?ifFileNotFoundThanThrowException=true

Was it helpful?

Solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top