error bc of 2 or more files
when i run this code it works fine if there is one file in the folder
but when i run the code and there is 2 or more files i get this error
COM.ibm.db2.jdbc.DB2Exception: [IBM][JDBC Driver] CLI0601E Invalid statement handle or statement is closed. SQLSTATE=S1000
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throwClosedError(Unknown Source)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.check_return_code(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2Statement.<init>(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2Statement.<init>(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2Connection.createStatement(Unknown Source)
at Unload.main(Unload.java:123)
i was trying to use a while and the hasMoreElements() but i am confusing myself - here is my code - can anyone make a suggestion please? thanks in advance annie :) cheers
import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.IOException;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.StringTokenizer;
publicstaticvoid main(String args[])
{
String folderName ="\\C:\\unload";//folder to read from
String processedFolderName ="\\C:\\unload_processed";//folder to transfer to
File f =new File(folderName);
File files[] = f.listFiles();
try
{
//StringTokenizer s = new StringTokenizer(files[], "", true); // need help here please?
while (true)//(s.hasMoreElements())
{
//make database connection
Connection conn;
Class.forName(COM_IBM_DB2_JDBC_APP_DB2DRIVER).newInstance();
conn = DriverManager.getConnection(JDBC_DB2 + SERVER, USERID, PWD);
for(int i = 0; i < files.length; i++)
{
if(files[i].isFile())
{
System.out.println(files[i]);
BufferedReader inStream =new BufferedReader(new FileReader(files[i]));
String line = inStream.readLine();
File list = files[i];
for(int c = 0; c < list.length(); c ++)
{
while(line !=null)
{
//System.out.print(line + "\n");//print the contents of the file by line
line = inStream.readLine();
}//while
}//for
inStream.close();
String loadid = files[i].toString();
loadid = loadid.substring(0, loadid.length()-4);//drop extension
String lastToken ="";
String input = loadid;
StringTokenizer st =new StringTokenizer(input,"\\", true);
while(st.hasMoreTokens())
{
String token = st.nextToken();
if(token.startsWith("\"") && token.endsWith("\""))
{
token = token.substring(1,token.length()-1);
}//if
lastToken = token.toString();
}//while
System.out.println(lastToken);
String segment = lastToken.toString();
StringTokenizer st1 =new StringTokenizer(segment,"-",true);
ArrayList seg =new ArrayList();
while(st1.hasMoreTokens())
{
String t = st1.nextToken();
if(!t.startsWith("-") && !t.endsWith("-"))
{
seg.add(t);
}//if
}//while
String agid = (String)seg.get(0);
String prinode = (String)seg.get(1);
String secnode = (String)seg.get(2);
String objname = (String)seg.get(3);
String firstdate = (String)seg.get(4);
String lastdate = (String)seg.get(5);
//query database to get application group name from application group id
Statement ps = conn.createStatement();
ResultSet rs = ps.executeQuery(" SELECT AGID, NAME FROM ROOT.TABTEST WHERE AGID = " + agid +" ;");
while(rs.next())
{
//set up the ARSADMIN unload command
String unload ="arsadmin unload -g " + rs.getString(2) +" -L " + agid +"-"+ prinode +"-"+ secnode +"-"+ objname +"-"+ firstdate +"-"+ lastdate +" -Q " +" -u " + USERID +" -p " + PWD;
System.out.println(unload);
}//while
rs.close();
ps.close();
conn.close();
}//if
}//for
}//while
}//try
catch(FileNotFoundException e)
{
System.out.println("FileNotFoundException: " + e.getMessage());
e.printStackTrace();
}//catch
catch(IOException e)
{
System.out.println("IOException: " + e.getMessage());
e.printStackTrace();
}//catch
catch(SQLException e)
{
System.out.println("SQLException: " + e.getMessage());
e.printStackTrace();
}//catch
catch(InstantiationException e)
{System.out.println("InstantiationException: " + e.getMessage());
e.printStackTrace();
}//catch
catch(IllegalAccessException e)
{
System.out.println("IllegalAccessException: " + e.getMessage());
e.printStackTrace();
}//catch
catch(ClassNotFoundException e)
{
System.out.println("ClassNotFoundException: " + e.getMessage());
e.printStackTrace();
}//catch
}//main

