我正在尝试以 .csv 格式编写整个 sql 表。该表有 6500 行长,但文件中只写了 600 行左右。每次运行该方法时,写入的行数都会有所不同
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();