Problems editing in Mysql and JSP

0

I have a problem with java and Mysql, I'm doing a web application with java in jsp, On a page I have the method that shows me a list of records in a table with a button to show the detail of each record, The detail I show it in a modal window created in boostrap, but the problem I have is when I press the edit button, it brings me all the ids of the records in the database table, and it should show only the id of the record that I select .

Here I leave the images.

When I press the button marked with red in the image, the modal that should bring only the selected id is displayed, but it brings all the ids of the records in the table.

Here is the html code where the first container nav has a form with a table of the list of records. The form is addressed to a servlet which is the one that returns the records of the database to the same table of the same page. The second container has the modal and this modal rescues the id of the records obtained in the first container through the button to edit.

<%@page import="negocio.Reserva"%>
<%@page import="java.util.ArrayList"%>
<% ArrayList<Reserva> adminReservas = (ArrayList<Reserva>)request.getSession().getAttribute("adminReservas");%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>


<br>
<!------------------------------INICIO CÓDIGO CONTENEDOR RESERVAS----------------------------------------------------> 
<nav class="nav navbar-nav navbar-center col-md-10">
<div class="container-fluid">
<div class="panel-heading bg-primary">Reservas</div>
<div class="panel-body panel panel-primary">
<form method="POST" action="AdministrarReservasServlet">
  <table class="table-condensed table-hover table-responsive">
            <tr class="">
                <th class="btn-info">N° Reserva</th>
                <th class="btn-info">Origen</th>
                <th class="btn-info">Destino</th>
                <th class="btn-info">Piezas</th>
                <th class="btn-info">Kilos</th>
                <th class="btn-info">Volumen</th>
                <th class="btn-info">Estado</th>
                <th class="btn-info">Acción</th>
            </tr>



<%
try
                      {

                      for(int i=0; i<adminReservas.size(); i++)
                                        {
                                            out.println("<tr>");
                                            out.println("<td><input type='text' value='"+adminReservas.get(i).getNumeroReserva()+"' class='input-sm form-control' size='5' readonly='readonly'></td>");
                                            out.println("<td><input type='text' value='"+adminReservas.get(i).getOrigenReserva()+"' class='input-sm form-control' size='5' readonly='readonly'></td>");
                                            out.println("<td><input type='text' value='"+adminReservas.get(i).getDestinoReserva()+"' class='input-sm form-control' size='5' readonly='readonly'></td>");
                                            out.println("<td><input type='text' value='"+adminReservas.get(i).getTotalPiezasReserva()+"' class='input-sm form-control' size='5' readonly='readonly'></td>");
                                            out.println("<td><input type='text' value='"+adminReservas.get(i).getTotalKilosReserva()+"' class='input-sm form-control' size='5' readonly='readonly'></td>");
                                            out.println("<td><input type='text' value='"+adminReservas.get(i).getTotalVolumenReserva()+"' class='input-sm form-control' size='5' readonly='readonly'></td>");
                                            out.println("<td><input type='text' value='"+adminReservas.get(i).getEstadoReserva()+"' class='input-sm form-control' size='8' readonly='readonly'></td>");
                                            out.println("<td><button type='button'  class='btn btn-primary glyphicon glyphicon-eye-open' data-toggle='modal' data-target='#modalAdministrarReservaDetalleReserva' style='font-size:19px'></button></td>");
                                        }   

                      }
                      catch(java.lang.NullPointerException ex)
                      {
                          ex.getMessage();
                          //out.print("<input type='text' value='"+ex.getMessage()+"'>");
                          out.print("</tr>");
                      }

%>

</table>
<input type="submit" name="btnMostrarReservas" value="Mostrar" class="btn btn-success">
<input type="button" name="btnVolver" value="VOLVER" class="btn btn-success" onclick="location.href='barraCentral.jsp'">
</form>
 </div>
</div>
</nav>


<!------------------------------FIN CÓDIGO CONTENEDOR RESERVAS---------------------------------------------------->
<!------------------------------------INICIO MODAL DETALLE DE RESERVA--------------------------------------------->

<nav class="nav navbar-nav navbar-center col-lg">


<div class="modal fade" id="modalAdministrarReservaDetalleReserva" tabindex="-1" role="dialog" aria-labelledby="modalAdministrarReservaDetalleReservaLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header bg-primary">
<h5 class="modal-title" id="modalAdministrarReservaDetalleReservaLabel">ADMINISTRAR RESERVAS - DETALLE RESERVA</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="left container-fluid">
<div class="panel-heading btn-info"><span class="glyphicon glyphicon-duplicate"></span></div>
<div class="panel-body panel">
<nav class="nav navbar-nav navbar-center col-lg"> 
<div class="left container-fluid">
<div class="panel-heading bg-default">DETALLE DE RESERVA</div>
<div class="panel-body panel panel-primary">
<form method="POST">
<b>Nº Reserva</b>
<%
try
                      {
                      for(int i=0; i<adminReservas.size(); i++)
{
out.println("<input type='text' value='"+adminReservas.get(i).getNumeroReserva()+"' class='input-sm' size='5' readonly='readonly'>");
}
}
catch(java.lang.NullPointerException ex)
                      {
out.print("<input type='text' value='"+ex.getMessage()+"'>");
                          out.print("</tr>");
}
%>
<input type="button" value="Modificar" class="btn btn-info"> 
</form>
</div>
</div>
</nav>
</div>
</div>
</div>
</div>
</div>
</div>
</nav>
<!------------------------------------FIN MODAL DETALLE DE RESERVA---------------------------------->
</body>
</html>

Here is the servlet code that obtains the data of the ReservationsDao class method. see Reserves Manage Reservations (), which obtains data from the database through the sql query.

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

ReservasDao mostrarReservaClienteDao=new ReservasDao();
    Usuario usuarioCliente=new Usuario();
    try
    {
 Connection conn = ConexionMysqlCargomove_db.getInstance().getConnection();
        ResultSet resultadoAdminReservas=mostrarReservaClienteDao.verReservasAdministrarReservas();

        ArrayList<Reserva>adminReservas=new ArrayList<Reserva>();

        if(resultadoAdminReservas==null)
        {
String errorAdminReservas="No se hay reservas creadas";
            request.getSession().setAttribute("errorAdminReservas", errorAdminReservas);
            request.getRequestDispatcher("errorAdministrarReservas.jsp").forward(request, response);
}
        else
        {
while(resultadoAdminReservas.next())
            {
                adminReservas.add(new Reserva(resultadoAdminReservas.getInt("COD_SEQ_RVAS"),resultadoAdminReservas.getString("ORI_DOC_RVAS"),resultadoAdminReservas.getString("DES_DOC__RVAS"),resultadoAdminReservas.getInt("TOTAL_PZS_RVAS"),resultadoAdminReservas.getDouble("TOTAL_KLS_RVAS"),resultadoAdminReservas.getDouble("TOTAL_VOL_RVAS"),resultadoAdminReservas.getString("EST_RVAS")));
            }
request.getSession().setAttribute("adminReservas", adminReservas);
            request.getRequestDispatcher("administrarReservas.jsp").forward(request, response);
 }

    }
    catch(SQLException ex)
    {
        java.util.logging.Logger.getLogger(AdministrarReservasServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
 }

Here is the code of the java class of the Dao package which is the one with the sql query.

public ResultSet verReservasAdministrarReservas()
{
    try {
        Connection conn=ConexionMysqlCargomove_db.getInstance().getConnection();
        st=(Statement)conn.createStatement();
        String SQL="";

        SQL="SELECT COD_SEQ_RVAS,ORI_DOC_RVAS,DES_DOC__RVAS,TOTAL_PZS_RVAS,TOTAL_KLS_RVAS,TOTAL_VOL_RVAS,EST_RVAS FROM RVAS;";

        res=st.executeQuery(SQL);
    } catch (SQLException ex) {
        java.util.logging.Logger.getLogger(ReservasDao.class.getName()).log(Level.SEVERE, null, ex.getStackTrace());
    }
    return res;
}
    
asked by Simón Pereira Vigouroux 03.11.2018 в 23:17
source

0 answers