Receive postgres table in java

0

I have the following function in postgresql:

CREATE OR REPLACE FUNCTION public.sp_sel_categoria(IN _codigo integer)
RETURNS TABLE(acat_cod smallint, acat_nombre character varying, acat_descrip character varying) AS
$BODY$
BEGIN
IF _codigo =-1 THEN
return query 
SELECT cat_cod, cat_nombre, cat_descrip
FROM categoria
order by cat_nombre;            
ELSE    
return query 
SELECT cat_cod, cat_nombre, cat_descrip
FROM categoria
WHERE cat_cod = _codigo
order by cat_nombre;    

END IF; 
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
ROWS 900001;
ALTER FUNCTION public.sp_sel_categoria(integer)
OWNER TO postgres;

When I receive it in java I do it in the following way:

while (resultado.next())
{
EntCategoria categoria = new EntCategoria();
categoria.setCodigo(resultado.getInt("acat_cod "));
categoria.setNombre(resultado.getString("acat_nombre "));
listCategorias.add(categoria);               
}

The problem arises because I want to receive it with the name of the column but I miss the following error:

The column name acat_cod was not found in this ResultSet.

and if I do it by column number it shows me the following error:

Bad value for type int: -, MEMORIES, "NOT DEFINED"

How do I get that table generated in postgres in java

    
asked by Leo T 19.09.2017 в 20:43
source

1 answer

0

To see the methods getters are to consult their headers are private getdata getName (); the getters methods do not receive parameters but they are returned by the solution:

while (resultado.next())
{
  EntCategoria categoria = new EntCategoria();
  categoria.setCodigo(resultado.getInt("acat_cod "));
  //eliminar parametros del metodo getInt()

  categoria.setNombre(resultado.getString("acat_nombre "));
  //eliminar parametros de la llamada a la funcion getString()

  listCategorias.add(categoria);               
}
    
answered by 20.09.2017 в 01:52