如何从多个数据库中读取项目?我已经知道可以从文件中获取.
以下示例适用于从多个文件中读取
...
<job id="readMultiFileJob" xmlns="http://www.springframework.org/schema/batch">
<step id="step1">
<tasklet>
<chunk reader="multiResourceReader" writer="flatFileItemWriter"
commit-interval="1" />
</tasklet>
</step>
</job>
...
<bean id="multiResourceReader"
class=" org.springframework.batch.item.file.MultiResourceItemReader">
<property name="resources" value="file:csv/inputs/domain-*.csv" />
<property name="delegate" ref="flatFileItemReader" />
</bean>
...
Run Code Online (Sandbox Code Playgroud)
像这样的三个豆子.
<bean id="database2" class="org.springframework.batch.item.database.JdbcCursorItemReader">
<property name="name" value="database2Reader" />
<property name="dataSource" ref="dataSource2" />
<property name="sql" value="select image from object where image like '%/images/%'" />
<property name="rowMapper">
<bean class="sym.batch.ImagesRowMapper2" />
</property>
</bean>
Run Code Online (Sandbox Code Playgroud) 我正在使用FlatFileItemReader处理CSV文件.
有时我在输入文件中得到空行.
当那件事发生时,整个步骤就停止了 我想跳过那些线并继续正常.
我试图在步骤中添加异常处理程序,以便捕获execption而不是整个步骤变为stooped:
@Bean
public Step processSnidUploadedFileStep() {
return stepBuilderFactory.get("processSnidFileStep")
.<MyDTO, MyDTO>chunk(numOfProcessingChunksPerFile)
.reader(snidFileReader(OVERRIDDEN_BY_EXPRESSION))
.processor(manualUploadAsyncItemProcessor())
.writer(manualUploadAsyncItemWriter())
.listener(logProcessListener)
.throttleLimit(20)
.taskExecutor(infrastructureConfigurationConfig.taskJobExecutor())
.exceptionHandler((context, throwable) -> logger.error("Skipping record on file. cause="+ ((FlatFileParseException)throwable).getCause()))
.build();
}
Run Code Online (Sandbox Code Playgroud)
由于当空行到达时我正在使用块进行处理并且捕获到异常,因此跳过整个块(块可能包含CSV文件上的有效行,并且它们也被跳过)
知道如何在处理文件时正确地执行此操作吗?
谢谢,雷.
编辑我的代码后.仍然没有跳过:
public Step processSnidUploadedFileStep() {
SimpleStepBuilder<MyDTO, MyDTO> builder = new SimpleStepBuilder<MyDTO, MyDTO>(stepBuilderFactory.get("processSnidFileStep"));
return builder
.<PushItemDTO, PushItemDTO>chunk(numOfProcessingChunksPerFile)
.faultTolerant().skip(FlatFileParseException.class)
.reader(snidFileReader(OVERRIDDEN_BY_EXPRESSION))
.processor(manualUploadAsyncItemProcessor())
.writer(manualUploadAsyncItemWriter())
.listener(logProcessListener)
.throttleLimit(20)
.taskExecutor(infrastructureConfigurationConfig.taskJobExecutor())
.build();
}
Run Code Online (Sandbox Code Playgroud) 所以我正在创建一个Spring Batch作业来读取CSV文件以及包含不完整数据的某些行; 它检查,输出到行不完整的日志,并跳过.它工作得很好,除了在工作结束时我希望它记录它找到的不完整的行数.只是一些简单的事情,比如"X不完整的行被发现".
我用谷歌搜索并寻找解决方案,但没有找到任何真正的东西.
任何帮助表示赞赏,需要更多信息.
我正在使用java,spring jdbc模板将n条记录插入到两个表中.有些像这样
假设正确配置了daos.xml.
ApplicationContext ctxt = new ClassPathXmlApplicationContext("daos.xml");
JdbcTemplate template = (JdbcTemplate) ctxt.getBean("jdbcTemplate");
final List<Person> list = new ArrayList<>();
final List<Role> roles = new ArrayList<>();
for(int i =1; i<=100; i++){
Person item = new Person();
item.setFirstName("Naveen" + i);
item.setLastName("kumar" + i);
item.setDescription("D" + i);
list.add(item);
Role role = new Role();
role.setName("Admin");
role.setCode("c" + i);
roles.add(role);
}
String sql = "insert into person(first_name, last_name, description) values(?,?,?)";
int[] arr = template.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws …Run Code Online (Sandbox Code Playgroud) 我正在使用Web服务方法来启动spring批处理作业.如果在Spring批处理控件中发生任何异常,则会返回处理器处理方法.但是我需要控制器回到web服务方法,我必须抓住并编写代码以通过电子邮件发送异常.
网络服务方式:
public void processInputFiles() throws ServiceFault {
String[] springConfig = { CONTEXT_FILE_NAME };
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
try {
setClientInfo();
JobLauncher jobLauncher = (JobLauncher) context.getBean(JOB_LAUNCHER);
Job job = (Job) context.getBean(REMITTANCE_JOB);
jobLauncher.run(job, new JobParameters());
}catch (Exception e) {
String errorMessage = "LockboxService exception:: Could not process Remittance(CSV) files";
final Message message = MessageFactory.createErrorMessage(MyService.class, errorMessage, e);
ErrorSenderFactory.getInstance().send(message, new Instruction[] { Instruction.ERROR_EMAIL });
}
Run Code Online (Sandbox Code Playgroud)
处理器处理方法:
@Override
public Transmission process(InputDetail remrow) throws ServiceException {
try {
business logic here
}
catch(Exception e) …Run Code Online (Sandbox Code Playgroud) 我是新手JAVA。我有一个配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="org.springframework.docs.test" />
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@192.168.1.217:1521:ksoradev"/>
<property name="username" value="pkrdm"/>
<property name="password" value="mypass"/>
</bean>
</beans>
Run Code Online (Sandbox Code Playgroud)
然后我的代码
public class Main {
public static void main(String args[]) throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext("context.config.xml");
DataSource dataSource = (DataSource) context.getBean("dataSource");
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
String lastName = jdbcTemplate.queryForObject(
"select a.firstname from TEST a",
new Object[]{1212L}, String.class);
System.out.println(lastName);
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,它返回错误无效的列索引。谁能帮我 ?
谢谢
如何在单个查询中更新DynamoDB中的多个记录?我有一个csv文件作为基于csv文件的输入我必须在DB中更新多个记录(只有一个属性).有没有可用的API?或者这可以使用批处理(Spring-batch)来完成?
spring ×5
java ×4
spring-batch ×4
count ×1
csv ×1
database ×1
jdbctemplate ×1
mysql ×1
rows ×1
spring-jdbc ×1
web-services ×1