I want the two rows of a count and groupby (sqlite)sql query to be displayed in the text area, but it is only displaying the first row.
When I place the conn.close()
statement outside the "while" block, it displays only the second row and leaves out the first row
@FXML
private void viewResult(ActionEvent event)
{
try
{
Connection conn = dbConnection.getConnection();
Statement resultStmt = conn.createStatement();
ResultSet rs = resultStmt.executeQuery("select candidate, count(candidate) from voteResult group by candidate");
while (rs.next()) {
String news = rs.getString(1)+" "+rs.getString(2);
this.result.setText(news);
conn.close();
}
}
catch (SQLException e)
{
System.err.println("Error " + e);
}
}
the expected result should be like this:
JOSEPH THANKGOD 4
ORJI DANIEL 1