The type of get (int) is erroneus

-2

I am new to the forum and do not put things with code and others, but I will try to explain all things JSP code

<%@ page language="java" %>
<%@ page import = "IDP_web.Herramientas.ListaJefaturas"%> 
<%@ page import = "IDP_web.Herramientas.Consultas"%> 
<%@ page import = "java.util.LinkedList"%> 
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="http://localhost:8080/ii/jefa.css">
    </head>
    <body>
        <form action="/IDP_web/s">
            <TABLE align="center">
                <TR>
                <tr>
                    <TH>C&oacutedigo de la Jefatura</TH> 
                    <TH>Nombre de la Jefatura</TH> 
                    <TH>Encargado de la jefatura</TH>
                </TR>
                <TR>
                <tr>
                    <td>codigo</td>
                    <td>Nombre</td>
                    <td>Encargado</td>
                </tr>
                <%
                    LinkedList<ListaJefaturas> lista = Herramientas.Consultas.getJefaturas();
                    for (int i = 0; i < lista.size(); i++) {
                        out.println("<tr>");
                        out.println("<td>" + lista.get(i).getcodigo() + "</td>");
                        out.println("<td>" + lista.get(i).getNombre() + "</td>");
                        out.println("<td>" + lista.get(i).getEncargado() + "</td>");
                        out.println("</tr>");
                    }
                %>
            </table>	

        </form>
    </body>
</html>

Code where I make the query to the database, Code is int, Name is varchar and Equal manager varchar

public static LinkedList<ListaJefaturas>  getJefaturas() {
    LinkedList<ListaJefaturas> lista = new LinkedList<ListaJefaturas>();
    try {

        Statement st = connect().createStatement();
        ResultSet rs = st.executeQuery("select Codigo,Nombre,Encargado from Jefas");
        while (rs.next()) {
            ListaJefaturas LJ = new ListaJefaturas();
            LJ.setCodigo(rs.getInt("Codigo"));
            LJ.setNombre(rs.getString("nombre"));
            LJ.setEncargado(rs.getString("Encargado"));
            lista.add(LJ);
        }
        rs.close();
        st.close();
        connect().close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return lista;
}

Class with the get and set

public class ListaJefaturas {

    private int Codigo;
    private String nombre;
    private String Encargado;

    public int getCodigo() {
        return Codigo;
    }

    public void setCodigo(int Codigo) {
        this.Codigo = Codigo;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getEncargado() {
        return Encargado;
    }

    public void setEncargado(String Encargado) {
        this.Encargado = Encargado;
    }
}

The error it displays is the following

    
asked by Andrey Varela Guzmán 24.10.2017 в 22:32
source

1 answer

0

In your JSP you see that you call getcodigo , while in your ListaJefaturas you define it as getCodigo() .

Another thing that could be happening is that in the class ListaJefaturas you try to get an int of your database, and normally the fields in the database are bigger, check with the class ResultSetMetadata the type of data of your ResultSet for that column I would say that it is BigDecimal .

Additionally, it is good practice to decouple to work with interfaces instead of implementations, that is:

List<ListaJefaturas> lista = Herramientas.Consultas.getJefaturas();

and in getJefaturas modify as

List getJefaturas() {
     List lista = new LinkedList();
     try {

        Statement st = connect().createStatement();
        ResultSet rs = st.executeQuery("select Codigo,Nombre,Encargado from Jefas");
        while (rs.next()) {
            ListaJefaturas LJ = new ListaJefaturas();
            LJ.setCodigo(rs.getInt("Codigo"));
            LJ.setNombre(rs.getString("Nombre"));
            LJ.setEncargado(rs.getString("Encargado"));
            lista.add(LJ);
        }
        rs.close();
        st.close();
        connect().close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return lista;
}
    
answered by 24.10.2017 в 22:40