Can I have H2 autocreate a schema in an in-memory database?

Yes, H2 supports executing SQL statements when connecting. You could run a script, or just a statement or two: String url = “jdbc:h2:mem:test;” + “INIT=CREATE SCHEMA IF NOT EXISTS TEST” String url = “jdbc:h2:mem:test;” + “INIT=CREATE SCHEMA IF NOT EXISTS TEST\\;” + “SET SCHEMA TEST”; String url = “jdbc:h2:mem;” + “INIT=RUNSCRIPT FROM ‘~/create.sql’\\;” + “RUNSCRIPT … Read more

H2 in-memory database. Table not found

DB_CLOSE_DELAY=-1 hbm2ddl closes the connection after creating the table, so h2 discards it. If you have your connection-url configured like this jdbc:h2:mem:test the content of the database is lost at the moment the last connection is closed. If you want to keep your content you have to configure the url like this jdbc:h2:mem:test;DB_CLOSE_DELAY=-1 If doing … Read more