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