i have 25 million record in my database and i want to retrieve it using java.my connection terminates after 5000 records. what should i do to keep my connection alive
package spliting;
import java.sql.*;
import java.util.ArrayList;
public class SpaceSpliting {
public Connection getConnection()
{
Connection con=null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","abc","abc");
}
catch(Exception e)
{
System.out.println(e);
}
return con;
}
public void addingValues()
{
int m=0,kk=0;
try
{
Connection con=getConnection();
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from owner");
while(rs.next())
{
String model=rs.getString(2);
System.out.println(model);
if(model==null)
{
kk++;
System.out.println(0+" "+kk);
m++;
}
else
{
String[] amodel=model.split(" ");
System.out.println(amodel.length);
if(amodel.length==1)
{
System.out.println("1");
Statement st1=con.createStatement();
st1.executeUpdate("update owner set maker='"+amodel[0]+"'where model_desc='"+model+"'");
kk++;
System.out.println("records updated"+" "+kk);
}
if(amodel.length==2)
{
System.out.println("2");
Statement st1=con.createStatement();
st1.executeUpdate("update owner set maker='"+amodel[0]+"',model1='"+amodel[1]+"' where model_desc='"+model+"'");
kk++;
System.out.println("records updated"+" "+kk);
}
if(amodel.length==3)
{
System.out.println("3");
Statement st1=con.createStatement();
st1.executeUpdate("update owner set maker='"+amodel[0]+"',model1='"+amodel[1]+"',model2='"+amodel[2]+"' where model_desc='"+model+"'");
kk++;
System.out.println("records updated"+" "+kk);
}
if(amodel.length>=4)
{
System.out.println("4");
Statement st1=con.createStatement();
st1.executeUpdate("update owner set maker='"+amodel[0]+"',model1='"+amodel[1]+"',model2='"+amodel[2]+"',model3='"+amodel[3]+"' where model_desc='"+model+"'");
kk++;
System.out.println("records updated"+" "+kk);
}
m++;
//con=getConnection();
}
if(m==50)
{
ArrayList al=new ArrayList();
al.add(rs);
//con.close();
con=getConnection();
rs=(ResultSet)al.get(0);
m=0;
}
}
//System.out.println("COLUMN ADDED");
}
catch(Exception e)
{
System.out.println(e);
}
}
public static void main(String[] args) {
SpaceSpliting ss=new SpaceSpliting();
//ss.addingColumn();
ss.addingValues();
// TODO Auto-generated method stub
}
}