Q:

Retrieve the data from the database and save results as lines in java lists

I query Oracle database using Java where I select 500 rows 40 colums each. When I have it in the result set (rs) then I would like to save the results as flat lines into the java list. I have something like this:
    while(rs.next()){
        String row="";
        for(int i=1; i<=columnCount; i++){
            row += " " + rs.getString(i);           
        }
         javaLIst.add(row);
    }

It works fine but it's not efficient at all. It takes about 16 seconds so I cannot afford this because I do that many times.
Can anyone tell me how I can retrieve data from database and save results to the java list in a more efficient way, please?

A:

I had a similar Issue earlier and I found that the problem is not with the logic or the way it was implemented. 
The issue was with the Fetch Size. Oracle JDBC (if I remember correctly) it is 10, so you are retrieving records from database after every 10 records i.e 50 times for 500 entries. 
Increase the Statement.Fetchsize to let's say 50 and see if this improves your performance. Tune this parameter as per your performance requirements. 
See if this link helps https://docs.oracle.com/cd/E18283_01/java.112/e16548/resltset.htm#i1023619
Hope this helps.

