/**
   * 批量执行sql文件
   *
   * @param connection jdbc 链接对象
   * @param sqlResourcePaths sql 文件路径
   * @throws java.sql.SQLException
   */
  private void executeScript(Connection connection, String... sqlResourcePaths)
      throws SQLException {

    for (String sqlResourcePath : sqlResourcePaths) {
      Resource resource = resourceLoader.getResource(sqlResourcePath);
      ScriptUtils.executeSqlScript(connection, resource);
    }
    connection.close();
  }
 /**
  * {@inheritDoc}
  *
  * @see #execute(DataSource)
  */
 @Override
 public void populate(Connection connection) throws ScriptException {
   Assert.notNull(connection, "Connection must not be null");
   for (Resource script : getScripts()) {
     ScriptUtils.executeSqlScript(
         connection,
         encodeScript(script),
         this.continueOnError,
         this.ignoreFailedDrops,
         this.commentPrefix,
         this.separator,
         this.blockCommentStartDelimiter,
         this.blockCommentEndDelimiter);
   }
 }
예제 #3
0
  /** Imports data into database by executing the sql datadump script */
  private void importData() {
    context = new AnnotationConfigApplicationContext(SpringConf.class);

    CustomResourceLoader customResourceLoader =
        (CustomResourceLoader) context.getBean("customResourceLoader");

    try {
      Resource query = customResourceLoader.getDataDumpResource(configFile.getDatadumpPath());
      ScriptUtils.executeSqlScript(dataSource.getConnection(), query);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ScriptException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }