I know there are similar threads for same title, but my question addresses different point. I am checking resultSet to see
whether query returns any value from rating
column if yes take the value and add it to arraylist
if no add 0.0
into arraylist(ratings).
In my code , else never gets executed resulting into no 0.0 in arraylist(for missing dates).Is my query going wrong somewhere? Please help.
String query = "SELECT * FROM DATA WHERE (dateofday BETWEEN ? AND ?) AND id = ?";
String mediapath = null;
try {
preparedStatement = connection.prepareStatement(query);
preparedStatement.setInt(3, Controller.id_logged_in);
preparedStatement.setString(1, datepickerfrom.getValue().toString());
preparedStatement.setString(2, datepickerto.getValue().toString());
resultSet = preparedStatement.executeQuery();
boolean flag = true;
if (resultSet.next()) {
do {
ratings.add(resultSet.getFloat("rating"));
countofday++;
}
while (resultSet.next());
} else {
ratings.add(Float.valueOf(0));
}
} catch (SQLException e) {
e.printStackTrace();
}finally {
connection.close();
}