Frage

I need to create H2 file db on demand(first connection) from backup-ed script. As I understand it could be done only by using two different urls:

  • jdbc:h2:file:sampledb;INIT=RUNSCRIPT FROM 'create.sql'; (Should be executed only one time)

  • jdbc:h2:file:sampledb;IFEXISTS=TRUE;

The problem is that in application connection to db is coming from JNDI so I should set up only one correct url. Does any ability exist to specify parameters based on some condition? And how to get this conditionn from H2? (Something like jdbc:h2:file:sampledb;!{dbixists}=runscript...). Or some ternary operation is allowed?

War es hilfreich?

Lösung

I would simply include IF NOT EXIST clauses inside the create.sql script and run it everytime. It would create the DB model only if there is no proper model at all.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top