线程“main”中的异常org.postgresql.util.PSQLException:错误:关系“ActivitySession”不存在

时间:2016-11-10 06:45:32

标签: java function jdbc prepared-statement callable-statement

我在postgres中有一个函数来解析名为ThirdPartyDataParse()的json记录,它看起来如下所示

CREATE OR REPLACE FUNCTION ThirdPartyDataParse()
RETURNS text AS $$
DECLARE 
sessionid NO SCROLL CURSOR FOR SELECT asn."Id",asn."UserId",asn."ActivityId",pd."DataSourceId",ad."Dump"
   FROM "Development"."ActivitySession" as asn inner join "Development"."PersonDataSource" as pd on pd."UserId" = asn."UserId" inner join "Development"."ActivitySessionDump" as ad 
   on asn."Id"=ad."ActivitySessionId" where asn."CreatedAt" between now() - interval '5 days' and now() and pd."DataSourceId"=1 for read only;
titles TEXT DEFAULT '';
rec record;
jsonrec record;
 BEGIN
 OPEN sessionid;
loop

FETCH sessionid INTO rec;
   if not found then
        exit ;
   end if;
   if rec."ActivityId"=1 and rec."DataSourceId"=1 then
    EXECUTE 'SELECT $1::json#>''{activities-steps,0}''->>''value'' as "steps"' INTO jsonrec USING rec."Dump";
   end if;
end loop;
return titles;
END;
$$ LANGUAGE plpgsql;

我在java中调用此函数

try (CallableStatement properCase = con.prepareCall("{? = call ThirdPartyDataParse() }")) {
  properCase.registerOutParameter( 1, Types.VARCHAR );
  properCase.execute();
}

但我在控制台

中遇到错误
Exception in thread "main" org.postgresql.util.PSQLException: ERROR: relation "ActivitySession" does not exist
  Where: PL/pgSQL function thirdpartydataparse() line 10 at OPEN
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2453)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2153)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:286)
    at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:432)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:358)
    at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:171)
    at org.postgresql.jdbc.PgCallableStatement.executeWithFlags(PgCallableStatement.java:81)
    at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:160)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.postgresql.ds.PGPooledConnection$StatementHandler.invoke(PGPooledConnection.java:426)
    at com.sun.proxy.$Proxy4.execute(Unknown Source)
    at oneraise.radis.thread.backgroundtask.ThirdPartyBackgoundTask.main(ThirdPartyBackgoundTask.java:173)

然后我删除了可调用语句&尝试准备好的声明仍然出错

我准备好的语句代码是

try (PreparedStatement stmt = backgroundobj.getDBConnection(prop).prepareStatement("select ThirdPartyDataParse()")) {
    stmt.execute();
}

例外是

Exception in thread "main" org.postgresql.util.PSQLException: ERROR: relation "ActivitySession" does not exist
  Where: PL/pgSQL function thirdpartydataparse() line 10 at OPEN
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2453)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2153)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:286)
    at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:432)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:358)
    at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:171)
    at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:160)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.postgresql.ds.PGPooledConnection$StatementHandler.invoke(PGPooledConnection.java:426)
    at com.sun.proxy.$Proxy3.execute(Unknown Source)
    at oneraise.radis.thread.backgroundtask.ThirdPartyBackgoundTask.main(ThirdPartyBackgoundTask.java:173)

0 个答案:

没有答案