Skip to Main Content

While writing data to csv last few records i.e 1415 records are missing in csv file

User_N7F07Jan 10 2023

Hello All!
I have below code which writes data to .csv file from database. All the records were writing to the file except last 1415 records. I have tried with both flush() and close() functions nothing works. Could someone help me to identify whats the issue with the code?
try{
ostream = new FileWriter(outputFile);
out = new BufferedWriter(ostream);
ResultSetMetaData meta = rs.getMetaData();
int numberOfColumns = meta.getColumnCount();
String dataHeaders = "\"" + meta.getColumnName(1) + "\"";
String row;
for (int i = 2; i < numberOfColumns + 1; i++) {
dataHeaders += ",\"" + meta.getColumnName(i).replaceAll("\"", "\\\"") + "\"";
}
out.write(dataHeaders);
while (rs.next()) {
for (int i = 2; i < numberOfColumns + 1; i++) {
row += ",\"" + rs.getString(i).replaceAll("\"", "\\\"") + "\"";
}
out.newLine();
out.write(row);
}
System.out.println("File Export Sucessful");
}
catch(Exception e)
{
System.out.println(e);
}
finally{
try{
out.close(); // out.flush();
ostream.close(); //ostream.flush();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}

Regards,
kotni

Comments
Post Details
Added on Jan 10 2023
5 comments
33 views