title: Is there any way for DBUnit to automatically create tables?
body: <p>I just realized that DBUnit doesn't create tables by itself (see <a href="https://stackoverflow.com/questions/1530951">How do I test with DBUnit with plain JDBC and HSQLDB without facing a NoSuchTableException?</a>).</p>
  
  <p>Is there any way for DBUnit to automatically create tables from a dataset or dtd?</p>
  
  <p><strong>EDIT:</strong>  For simple testing of an in-memory database like HSQLDB, a crude approach can be used to automatically create tables:</p>
  
  <pre><code>private void createHsqldbTables(IDataSet dataSet, Connection connection) throws DataSetException, SQLException {
      String[] tableNames = dataSet.getTableNames();
  
      String sql = "";
      for (String tableName : tableNames) {
        ITable table = dataSet.getTable(tableName);
        ITableMetaData metadata = table.getTableMetaData();
        Column[] columns = metadata.getColumns();
  
        sql += "create table " + tableName + "( ";
        boolean first = true;
        for (Column column : columns) {
          if (!first) {
            sql += ", ";
          }
          String columnName = column.getColumnName();
          String type = resolveType((String) table.getValue(0, columnName));
          sql += columnName + " " + type;
          if (first) {
            sql += " primary key";
            first = false;
          }
        }
        sql += "); ";
      }
      PreparedStatement pp = connection.prepareStatement(sql);
      pp.executeUpdate();
  }
  
  private String resolveType(String str) {
    try {
      if (new Double(str).toString().equals(str)) {
        return "double";
      }
      if (new Integer(str).toString().equals(str)) {
        return "int";
      }
    } catch (Exception e) {}
  
    return "varchar";
  }
  </code></pre>