• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Spring batch Oracle connection

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
reply
    Bookmark Topic Watch Topic
  • New Topic