I am trying to write an entire sql table in .csv format. The table is 6500 lines long, but only 600 or so lines are written in the file. The number of lines written varies a bit every time I run the method
Connection con = Panel.getConnection();
String query = "SELECT * from group3.merged_person";
PreparedStatement statement = con.prepareStatement(query);
ResultSet srs = statement.executeQuery();
int totalColumns = srs.getMetaData().getColumnCount();
FileWriter writer = new FileWriter("merged_person.csv");
for(int i = 1; i <= totalColumns; i++) {
writer.write(srs.getMetaData().getColumnLabel(i) + ",");
}
writer.write("\n");
int lines = 0;
while(srs.next()) {
lines++;
for(int j = 1; j <= totalColumns; j++) {
writer.write(srs.getString(j) + ",");
}
writer.write("\n");
}
System.out.println("lines written " + lines);
writer.close();