I must use PostgreSQL but I have a little problem when I try to read a function in Java.
My function:
CREATE OR REPLACE FUNCTION tiena.RecursosData7(x text, OUT id text, OUT valor text)RETURNS SETOF record
AS
'
SELECT recursodc.idrecursodc, recursodc.valorfonte
FROM tiena.recursodc
WHERE valorfonte=$1;
'
LANGUAGE 'sql';
Then in Java I’m trying to read the function this way:
try {
if (AbrirConexao()) {
conn.setAutoCommit(false);
proc = conn.prepareCall("{ call tiena.recursosdata7(?,?, ?)}");
proc.setString(1,"IG - SP");
proc.registerOutParameter(2, Types.VARCHAR);
proc.registerOutParameter(3, Types.VARCHAR);
//proc.execute();
//resSet = (ResultSet) proc.getObject(1);
resSet = proc.executeQuery();
while(resSet.next())
{
String id = resSet.getString(1);
String fonte = resSet.getString(2);
System.out.println("id : "+ id +", fonte: "+ fonte);
}
proc.close();
}
But I always get the same error.
Erro : Nenhum resultado foi retornado pela consulta.
org.postgresql.util.PSQLException: Nenhum resultado foi retornado pela consulta.
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:274)
at LerArquivos.ConexaoBD.RecuperarIDRecurso2(ConexaoBD.java:117)
at upload_cg.Main.main(Main.java:24)
I tried to move the location of the parameters, the function and i search a lot but I don’t found the solution. Do you have any suggestions?
Bellninita, consider using a cursor instead. Here are example Java and SQL code that has components similar to what you appear to need. This is similar to the production code used for the same purpose:
Here is the SQL that is inside the function (aka, Stored Procedure):