title: Running a script to create tables with HSQLDB
body: <p>I use <strong>hsqldb</strong> to run my unit tests that need a database access.</p>
  
  <p>For the moment, when I want to create a table for a specific test, I have the following code:</p>
  
  <pre><code>private void createTable() {
      PreparedStatement ps;
      try {
          ps = getConnection().prepareStatement("CREATE TABLE T_DATE (ID NUMERIC PRIMARY KEY, DATEID TIMESTAMP)");
          ps.executeUpdate();
      } catch (SQLException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>The <code>getConnection()</code> method retrieve a DataSource defined in a <code>Spring</code> context:</p>
  
  <pre><code>&lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;property name="driverClassName" value="org.hsqldb.jdbcDriver"/&gt;
      &lt;property name="url" value="jdbc:hsqldb:mem:memoryDB"/&gt;
      &lt;property name="username" value="SA"/&gt;
      &lt;property name="password" value=""/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Now, I want to create my table from a SQL script (of course, this script will contain more than one table creation):</p>
  
  <pre><code>CREATE TABLE T_DATE_FOO (ID NUMERIC PRIMARY KEY, DATEID TIMESTAMP);
  CREATE TABLE T_DATE_BAR (ID NUMERIC PRIMARY KEY, DATEID TIMESTAMP);
  ...
  </code></pre>
  
  <p>I've seen in the HSQLDB documentation that I can ask him to <a href="http://hsqldb.org/doc/2.0/util-guide/sqltool-chapt.html#N107D5" rel="noreferrer">run a script at the startup</a>. However, it does not meet my requirements, as I want to run a script at the runtime.</p>
  
  <p>Of course, I can read the file myself, and for every SQL statement, I run a <code>ps.executeUpdate()</code> command, but I don't want to use this kind of solution (except if there are no other solution).</p>
  
  <p>Any idea?</p>