The title says it all. This is my ResultSet code:
try {
while (rs.next()) {
int ID = rs.getInt("ID");
String Name = rs.getString("Name");
String CountryCode = rs.getString("CountryCode");
String District = rs.getString("District");
int Population = rs.getInt("Population");
//Display values
try {
writeToFile(ID, Name, CountryCode, District, Population);
} catch (IOException e) {
e.printStackTrace();
}
}
This is my writeToFile method:
public void writeToFile(int id, String name, String countryCode, String district, int population) throws IOException {
FileWriter fw = new FileWriter("C:\\Users\\horry\\Desktop\\results.txt");
fw.write(id + " " + name + " " + countryCode + " " + district + " " + population + "\n");
try {
fw.flush();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Ive tried the usual flush and close method but something is missing. Should the filewriter be declared elsewgere?