title: How to populate H2 in-memory DB from a file (populate.sql)?
body: <p>I want to add H2 in-memory db to my Spring MVC application. For ORM I’m using Hibernate. Here is my configs:</p>
  
  <p>[hibernate.cfg.xml]</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="hibernate.connection.driver_class"&gt;org.h2.Driver&lt;/property&gt;
          &lt;property name="hibernate.connection.url"&gt;jdbc:h2:~/myDB&lt;/property&gt;
          &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.H2Dialect&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;sa&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;qwerty&lt;/property&gt;
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
          &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;
          &lt;mapping class="de.alf.h2.entity.Student"/&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>[data.xml]</p>
  
  <pre><code>&lt;bean:beans xmlns:bean="http://www.springframework.org/schema/beans"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:tx="http://www.springframework.org/schema/tx"
              xmlns:ctx="http://www.springframework.org/schema/context"
              xsi:schemaLocation="http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/tx
              http://www.springframework.org/schema/tx/spring-tx.xsd
              http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
      &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
      &lt;ctx:component-scan base-package="de.alf.h2.repository"/&gt;
      &lt;bean:bean id="template" class="org.springframework.orm.hibernate3.HibernateTemplate"&gt;
          &lt;bean:property name="sessionFactory" ref="sessionFactory"/&gt;
      &lt;/bean:bean&gt;
      &lt;bean:bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
          &lt;bean:property name="configLocation" value="classpath:/hibernate/hibernate.cfg.xml"/&gt;
      &lt;/bean:bean&gt;
      &lt;bean:bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
          &lt;bean:property name="sessionFactory" ref="sessionFactory"/&gt;
      &lt;/bean:bean&gt;
  &lt;/bean:beans&gt;
  </code></pre>
  
  <p>[web.xml]</p>
  
  <pre><code>&lt;web-app version="2.4"
      xmlns="http://java.sun.com/xml/ns/j2ee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
      http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;/WEB-INF/mvc.xml&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/data.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>I need to create db from a file (resource/db/data.sql).</p>
  
  <pre><code>CREATE TABLE student {
    id INT NOT NULL AUTO_INCREMENT,
    name VARCHAR (250)
  }
  </code></pre>
  
  <p>How to do this in my code?</p>