Estou tentando pegar o ultimo registro de uma tabela, o código funciona normalmente no xampp, mas quanto tento rodar ele, os valores sempre voltam zerados, eis os códigos
classe do banco
public Registros obterUltimoRegistro(Registros registros) throws SQLException {
Registros retorno = null;
Statement st = null;
ResultSet rs = null;
try {
st = conn.createStatement();
String sql = "SELECT * FROM registros where FUNCIONARIO_id_funcionario_func = 1 order by ID_REGISTRO desc limit 1 ;";
rs = st.executeQuery(sql);
if (rs.next()) {
retorno = new Registros();
retorno.setIdRegistro(rs.getInt("ID_REGISTRO"));
retorno.setIdTipoRegistro(rs.getInt("TIPO_REGISTRO_ID_TIPO_REGISTRO_TREG"));
retorno.setData(rs.getString("DT_DIA_REG"));
retorno.setHora(rs.getString("DT_HORARIO_REG"));
retorno.setIdFuncionario(rs.getInt("FUNCIONARIO_id_funcionario_func"));
}
return retorno;
} finally {
st.close();
rs.close();
}
}
Servlet
protected void doService(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
try{
Registros ultimoRegistro = new Registros();
RegistrosDao registrosDao = new RegistrosDao();
registrosDao.obterUltimoRegistro(ultimoRegistro);
request.setAttribute("ultimoRegistro", ultimoRegistro);
getServletContext().getRequestDispatcher("/teste.jsp")
.forward(request, response);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Alguem tem alguma idéia do que pode estar errada?