0
I want to send the result of a SELECT COUNT(*) FROM tabela
for an input text box on the jsp page:
On the page dao I have:
public int getRowNumber() throws SQLException {
int numberRow = 0;
String sql = "SELECT COUNT(*) FROM usuario";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
ResultSet resultset = preparedStatement.executeQuery();
while(resultset.next()){
numberRow = resultset.getInt("count(*)");
}
return numberRow;
}
In Servlet I did:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().append("Served at: ").append(request.getContextPath());
RequestDispatcher view = request.getRequestDispatcher("cadastroUsuario.jsp");
try {
request.setAttribute("usuarios", daoUsuario.getRowNumber());
} catch (SQLException e) {
e.printStackTrace();
}
view.forward(request, response);
}
On the jsp page I’m lost:
<%= ??? %>