Spring batch 之操作数据库

common.xml



	
	
	
	
	
		
	
	
	
	
		
		
		

		
		
		
		
		
		
		
		
		
		

		

		
		
		
		

		
		
		
		

		
		
		
		
		
		

		
		
		
	


jdbcJob.xml




	
		
			
		
	

	
		
		
			
				insert into script_cmd values(1,2,3)
			
		
	

HelloJdbc.java

package com.yang.batch.helloworld;

import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.jdbc.core.JdbcTemplate;

public class HelloJdbc implements Tasklet {

	private JdbcTemplate jdbcTemplate;
	
	private String sql;

	@Override
	public RepeatStatus execute(StepContribution arg0, ChunkContext arg1)
			throws Exception {
		System.out.println("JDBC.......");
		this.jdbcTemplate.execute(this.sql);
		
		return null;
	}

	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	public String getSql() {
		return sql;
	}

	public void setSql(String sql) {
		this.sql = sql;
	}
}



你可能感兴趣的:(Spring batch 之操作数据库)