I am trying to display some data from my database with the following method but it only shows NULL values. I am not sure I have the right implementation of the method so if there's anything I should change when calling the select() method. Thank you in advance for any help.
//SELECT method
public Res select(int id) {
Res res = new Res();
Connection connection = null;
PreparedStatement preparedStm = null;
ResultSet resultSet = null;
try {
connection = ConnectionConfiguration.getConnection();
preparedStm = connection.prepareStatement("SELECT * FROM res WHERE id = ?");
preparedStm.setInt(1, id);
resultSet = preparedStm.executeQuery();
while(resultSet.next()) {
res.setId(resultSet.getInt("id"));
res.setDay(resultSet.getString("res"));
res.setNoRooms(resultSet.getString("rooms"));
res.setNoNights(resultSet.getString("nights"));
res.setRoomType(resultSet.getString("room_type"));
res.setUser_email(resultSet.getString("email"));
}
} catch(Exception e) {
e.printStackTrace();
} finally {
if (resultSet != null) {
try {
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (preparedStm != null) {
try {
preparedStm.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return res;
}
//JSP Page display
<h1 align="center"> Reservation </h1><br>
<% Reservation r = new Reservation();
Res rb = new Res();
r.select(rb.getId());
%>
<table border="1" width="50%" align="center">
<tr><th colspan="3">Date</th><th>Rooms</th><th>Nights</th><th>Room type</th><th>
Comments</th><th>Status</th></tr>
<tr><td><%= rb.getDay() %><td>
<%=rb.getRooms() %></td><td><%=rb.getNights() %></td><td><%=rb.getRoomType() %></td>
</table>