我正在嘗試從 SQL 文件創建內存中的 H2 數據庫,如文檔中所示。我將tables.sql文件保存在src/main/resources/sql/文件夾中,并嘗試按如下方式創建數據庫。 public static HikariConfig getHikariConfigH2(String schema, String pathToSchemaSql) { HikariConfig config = new HikariConfig(); config.setJdbcUrl("jdbc:h2:mem:" + schema + ";DATABASE_TO_UPPER=false;" + "MODE=MySQL" + ";DB_CLOSE_DELAY=-1" + ";INIT=create schema if not exists " + schema + "\\;SET SCHEMA " + schema + "\\;" + "INIT=runscript from '" + pathToSchemaSql + "'" ); config.setUsername("sa"); config.setPassword(""); return config; } public void testSetup() {?> HikariConfig configurationMaster = getHikariConfigH2("schema_name", "src/main/resources/sql/tables.sql"); DataSource master = new HikariDataSource(configurationMaster); }tables.sql 文件的內容是CREATE TABLE item_types ( id int NOT NULL, typeName varchar(50) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;我不確定為什么它期待插入語句。有人可以幫忙嗎
1 回答

守著一只汪
TA貢獻1872條經驗 獲得超4個贊
您需要INIT=
從連接 URL 中的 SQL 命令中間刪除意外的秒數。
+ ";INIT=create schema if not exists " + schema + "\\;SET SCHEMA " + schema + "\\;" + /* problem was here */ "runscript from '" + pathToSchemaSql + "'"
添加回答
舉報
0/150
提交
取消