简体   繁体   English

Spring批处理将SQL脚本作为Tasklet运行

[英]spring batch run sql script as a tasklet

Does spring batch support executing a sql scripts as part of a tasklet? Spring Batch是否支持将SQL脚本作为Tasklet的一部分执行? Below are the sequence of steps that I'm planning to develop with spring batch. 以下是我计划使用Spring Batch开发的步骤序列。

For step 2 and 4 I need to run bunch of sql statements in sequence. 对于步骤2和4,我需要按顺序运行一堆sql语句。 How can I accomplish running a sql script? 如何完成运行SQL脚本?

  1. Read csv files and validate the contents 读取csv文件并验证内容
  2. if valid content, Execute a sql script that drop existing tables, and re-create tables, index etc 如果内容有效,请执行删除现有表的sql脚本,然后重新创建表,索引等
  3. Run the writer operations to insert the data into the table. 运行编写器操作以将数据插入表中。
  4. Run sequence of stored procedures described in the .sql file. .sql文件中描述的存储过程的运行顺序。

While I don't believe Spring Batch specifically supports what you're asking for, you could take a look at ScriptUtils to see if it provides the behavior you're looking for. 虽然我不认为Spring Batch特别支持您的要求,但是您可以查看ScriptUtils来查看它是否提供了您想要的行为。

If not, depending on the complexity of your SQL there is the option of using JdbcTemplate directly within a Tasklet and creating a series of Tasklets 如果不是,则根据您的SQL的复杂性,可以选择直接在Tasklet中使用JdbcTemplate并创建一系列Tasklets

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM