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

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

– Start


假设我们有如下定长文件(people_20170716.txt)

header1       zhangsan                       2       lisi                           3       wangwu                         footer

需要导入如下表中

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

来看看如何配置这个 job 吧

header
footer
package shangbo.springbatch.example3;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.example3;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/example3/LoadFileJob.xml");		// job 和 job 参数		Map
parameters = new HashMap<>(); parameters.put("business_date", new JobParameter("20170716")); 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-16
– Written by ShangBo on 2017-07-16
– End

你可能感兴趣的文章
Node.js中的事件驱动编程详解
查看>>
mongodb 命令
查看>>
MongoDB基本使用
查看>>
mongodb管理与安全认证
查看>>
nodejs内存控制
查看>>
nodejs Stream使用中的陷阱
查看>>
MongoDB 数据文件备份与恢复
查看>>
数据库索引介绍及使用
查看>>
MongoDB数据库插入、更新和删除操作详解
查看>>
MongoDB文档(Document)全局唯一ID的设计思路
查看>>
mongoDB简介
查看>>
Redis持久化存储(AOF与RDB两种模式)
查看>>
memcached工作原理与优化建议
查看>>
Redis与Memcached的区别
查看>>
redis sharding方案
查看>>
程序员最核心的竞争力是什么?
查看>>
Node.js机制及原理理解初步
查看>>
linux CPU个数查看
查看>>
分布式应用开发相关的面试题收集
查看>>
简单理解Socket及TCP/IP、Http、Socket的区别
查看>>