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; 
}

Recommended Answers

All 6 Replies

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

Why is it not feasible?

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++;
}

That code seems to do what your topic title asked, so what exactly is your question now?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.