博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring Batch 例子: 导入分隔符文件到数据库
阅读量:4049 次
发布时间:2019-05-25

本文共 2579 字,大约阅读时间需要 8 分钟。

– Start


假设我们有如下分隔符文件(people_20170711.txt)

header1|zhangsan2|lisi3|wangwufooter

需要导入如下表中

CREATE TABLE PEOPLE(	ID    NUMBER(8,0), 	NAME  VARCHAR2(30));

来看看如何配置这个 job 吧

header
footer
package shangbo.springbatch.example2;public class People implements java.io.Serializable{	private static final long serialVersionUID = 8904705906008476310L;		private Integer id;	private String name;	public Integer getId() {		return id;	}	public void setId(Integer id) {		this.id = id;	}	public String getName() {		return name;	}	public void setName(String name) {		this.name = name;	}}
package shangbo.springbatch.example2;import java.util.HashMap;import java.util.Map;import org.springframework.batch.core.Job;import org.springframework.batch.core.JobParameter;import org.springframework.batch.core.JobParameters;import org.springframework.batch.core.JobParametersInvalidException;import org.springframework.batch.core.launch.JobLauncher;import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;import org.springframework.batch.core.repository.JobRestartException;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class App {	public static void main(String[] args) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException {		ApplicationContext context = new ClassPathXmlApplicationContext("shangbo/springbatch/example2/LoadFileJob.xml");		// job 和 job 参数		Map
parameters = new HashMap<>(); parameters.put("business_date", new JobParameter("20170711")); JobParameters jobParameters = new JobParameters(parameters); Job job = context.getBean(Job.class); // 运行 job JobLauncher jobLauncher = context.getBean(JobLauncher.class); jobLauncher.run(job, jobParameters); }}

– 声 明:转载请注明出处
– Last Updated on 2017-07-15
– Written by ShangBo on 2017-07-15
– End

你可能感兴趣的文章
机器学习实战之决策树二
查看>>
[LeetCode By Python]7 Reverse Integer
查看>>
[LeetCode By Python]121. Best Time to Buy and Sell Stock
查看>>
[LeetCode By Python]122. Best Time to Buy and Sell Stock II
查看>>
[LeetCode By Python]125. Valid Palindrome
查看>>
[LeetCode By Python]136. Single Number
查看>>
Android/Linux 内存监视
查看>>
Android2.1消息应用(Messaging)源码学习笔记
查看>>
MPMoviePlayerViewController和MPMoviePlayerController的使用
查看>>
CocoaPods实践之制作篇
查看>>
[Mac]Mac 操作系统 常见技巧
查看>>
苹果Swift编程语言入门教程【中文版】
查看>>
捕鱼忍者(ninja fishing)之游戏指南+游戏攻略+游戏体验
查看>>
iphone开发基础之objective-c学习
查看>>
iphone开发之SDK研究(待续)
查看>>
计算机网络复习要点
查看>>
Variable property attributes or Modifiers in iOS
查看>>
NSNotificationCenter 用法总结
查看>>
C primer plus 基础总结(一)
查看>>
剑指offer算法题分析与整理(三)
查看>>