title: H2 database - creating table form a sql file
body: <p>I am trying to create an in-memory H2 database from a SQL file as shown in the <a href="http://www.h2database.com/html/features.html#in_memory_databases" rel="nofollow noreferrer">docs</a>.</p>
  
  <p>I kept my <strong>tables.sql</strong> file in <strong>src/main/resources/sql/</strong> folder and  try to create the db as follows.</p>
  
  <blockquote>
  <pre><code>  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() { &gt;               HikariConfig configurationMaster = getHikariConfigH2("schema_name",
                    "src/main/resources/sql/tables.sql");
            DataSource master = new HikariDataSource(configurationMaster);
         }
  </code></pre>
  </blockquote>
  
  <p>But it fails with following exception</p>
  
  <pre><code>org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "INIT[*]=runscript from 'src/main/resources/sql/tables.sql'"; expected "INSERT"; SQL statement:
  INIT=runscript from 'src/main/resources/sql/tables.sql' [42001-199]
      at org.h2.message.DbException.getJdbcSQLException(DbException.java:451) ~[h2-1.4.199.jar:1.4.199]
      at org.h2.message.DbException.getJdbcSQLException(DbException.java:427) ~[h2-1.4.199.jar:1.4.199]
      at org.h2.message.DbException.getSyntaxError(DbException.java:243) ~[h2-1.4.199.jar:1.4.199]
      at org.h2.command.Parser.getSyntaxError(Parser.java:991) ~[h2-1.4.199.jar:1.4.199]
      at org.h2.command.Parser.parsePrepared(Parser.java:951) ~[h2-1.4.199.jar:1.4.199]
      at org.h2.command.Parser.parse(Parser.java:788) ~[h2-1.4.199.jar:1.4.199]
      at org.h2.command.Parser.parse(Parser.java:764) ~[h2-1.4.199.jar:1.4.199]
      at org.h2.command.Parser.prepareCommand(Parser.java:683) ~[h2-1.4.199.jar:1.4.199]
      at org.h2.engine.Session.prepareLocal(Session.java:627) ~[h2-1.4.199.jar:1.4.199]
      at org.h2.command.CommandList.executeRemaining(CommandList.java:50) ~[h2-1.4.199.jar:1.4.199]
      at org.h2.command.CommandList.update(CommandList.java:63) ~[h2-1.4.199.jar:1.4.199]
      at org.h2.command.Command.executeUpdate(Command.java:267) ~[h2-1.4.199.jar:1.4.199]
      at org.h2.engine.Engine.openSession(Engine.java:252) ~[h2-1.4.199.jar:1.4.199]
      at org.h2.engine.Engine.createSessionAndValidate(Engine.java:178) ~[h2-1.4.199.jar:1.4.199]
      at org.h2.engine.Engine.createSession(Engine.java:161) ~[h2-1.4.199.jar:1.4.199]
      at org.h2.engine.Engine.createSession(Engine.java:31) ~[h2-1.4.199.jar:1.4.199]
      at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:336) ~[h2-1.4.199.jar:1.4.199]
      at org.h2.jdbc.JdbcConnection.&lt;init&gt;(JdbcConnection.java:169) ~[h2-1.4.199.jar:1.4.199]
      at org.h2.jdbc.JdbcConnection.&lt;init&gt;(JdbcConnection.java:148) ~[h2-1.4.199.jar:1.4.199]
      at org.h2.Driver.connect(Driver.java:69) ~[h2-1.4.199.jar:1.4.199]
      at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136) ~[HikariCP-3.2.0.jar:na]
      at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369) ~[HikariCP-3.2.0.jar:na]
      at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198) ~[HikariCP-3.2.0.jar:na]
      at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467) [HikariCP-3.2.0.jar:na]
      at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541) [HikariCP-3.2.0.jar:na]
      at com.zaxxer.hikari.pool.HikariPool.&lt;init&gt;(HikariPool.java:115) [HikariCP-3.2.0.jar:na]
      at com.zaxxer.hikari.HikariDataSource.&lt;init&gt;(HikariDataSource.java:81) [HikariCP-3.2.0.jar:na]
  </code></pre>
  
  <p>Content of the tables.sql file is </p>
  
  <pre><code>CREATE TABLE item_types (
      id int NOT NULL,
      typeName varchar(50) NOT NULL,
      PRIMARY KEY (`id`)
  )   ENGINE=InnoDB DEFAULT CHARSET=utf8;
  </code></pre>
  
  <p>I am not sure why it’s expecting an insert statement.</p>
  
  <p>Could someone please help</p>