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

后端 未结 5 1993
逝去的感伤
逝去的感伤 2020-11-30 20:36

(I\'ve already seen the H2 database In memory - Init schema via Spring/Hibernate question; it is not applicable here.)

I\'d like to know if there\'s a setting in H2

5条回答
  •  遥遥无期
    2020-11-30 21:07

    What Thomas has written is correct, in addition to that, if you want to initialize multiple schemas you can use the following. Note there is a \\; separating the two create statements.

        EmbeddedDatabase db = new EmbeddedDatabaseBuilder()
                        .setType(EmbeddedDatabaseType.H2)
                        .setName("testDb;DB_CLOSE_ON_EXIT=FALSE;MODE=Oracle;INIT=create " +
                                "schema if not exists " +
                                "schema_a\\;create schema if not exists schema_b;" +
                                "DB_CLOSE_DELAY=-1;")
                        .addScript("sql/provPlan/createTable.sql")
                        .addScript("sql/provPlan/insertData.sql")
                        .addScript("sql/provPlan/insertSpecRel.sql")
                        .build();
    

    ref : http://www.h2database.com/html/features.html#execute_sql_on_connection

提交回复
热议问题