SELECT * FROM myTable WHERE columnId < 45; 





while (rs.next(){ 
result of row1 goes to row1.txt; 
result of row2 goes to row2.txt; 
result of row3 goes to row3.txt; 
result of row4 goes to row4.txt; 
}

Unwrap your loop, ie

SELECT * FROM myTable WHERE columnId < 45...

result of current row goes to row1.txt;
rs.next();
result of current row goes to row2.txt;
rs.next();
result of current row goes to row3.txt;
rs.next();
result of current row goes to row4.txt;

(or maybe it would be better to have an array of rows for the reuslts?)

How would I have the array for the results since they are going to be returned with a single select statement as the first option does not seem feasible

Edited 3 Years Ago by laolumichael: additional information

It is not feasible because what I have is as stated below:

FileOutputStream fop;
int counter = 1;
ResultSet result = statement.executeQuery("SELECT * FROM myTable WHERE columnID < 45");
while (result.next()){
    File file = new File("C:/result"+counter+".txt");
    fop = new FileOutputStream(file);
    String output = result.getString(1);
    byte[] byteValue = output.getBytes();           
    fop.write(byteValue);
    fop.close();
    count++;
}

And yes, the code above finally solves the problem. I just noticed that now. Thanks everyone for your help

This question has already been answered. Start a new discussion instead.