Example #1
0
  public static boolean initDatabase(Configuration config) {
    try (Connection connection = Database.getConnection(config);
        Statement statement = connection.createStatement()) {
      Scanner s = new Scanner(FileUtil.getInputStreamFrom(PATH_TO_SQL_SCRIPT));
      s.useDelimiter("(;(\r)?\n)|(--\n)");
      while (s.hasNext()) {
        String line = s.next();
        if (line.startsWith("/*!") && line.endsWith("*/")) {
          int i = line.indexOf(' ');
          line = line.substring(i + 1, line.length() - " */".length());
        }

        if (line.trim().length() > 0) {
          statement.execute(line);
        }
      }
    } catch (SQLException | FileNotFoundException ex) {
      ex.printStackTrace();
      return false;
    }
    return true;
  }