I have written a spring batch code,
Following is the properties file:
batch.jdbc.testWhileIdle=false
batch.schema=
batch.data.source.init=false
batch.jdbc.max.active=100
batch.jdbc.driver=oracle.jdbc.OracleDriver
batch.jdbc.url=jdbc:oracle:thin:@********
batch.jdbc.user=***
batch.jdbc.password=**************
batch.schema.script=*************
batch.drop.script=*****************************
batch.business.schema.script=classpath*:/business-schema-oracle10g.sql
batch.jdbc.max.active=100
Connection is also succesfully established.
But my area of worry is how should i use this connection in my implementation of ItemReader class. I want to connect to the oracle database in my implementation of ItemReader class:
package com.bestbuy.batch.reader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.springframework.batch.item.ItemReader;
public class Reader implements ItemReader<
String> {
public String read() throws Exception, UnexpectedInputException,
ParseException, NonTransientResourceException {
try{
String name = null;
Connection conn = null;
PreparedStatement ps = null;
//Connection code needed here
String sqlQuery = "select * from temp_table where id=?";
ResultSet rs=null;
int ID =190;
for(int i=0;i<50;i++){
ps = conn.prepareStatement(sqlQuery);
ps.setInt(1,ID);
rs= ps.executeQuery();
while (rs.next()){
String firstName = rs.getString("Name");
return firstName;
}
ID++;
}
}
catch(Exception e){
System.out.println("Exception in Reader");
}
return null;
}
}
Please help!