Exception in thread "main" org.postgresql.util.PSQLException: ERROR: relation "ActivitySession" does not exist
<p>I have a function in postgres to parse json records called ThirdPartyDataParse() and it looks like below</p>

<pre><code>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#&gt;''{activities-steps,0}''-&gt;&gt;''value'' as "steps"' INTO jsonrec USING rec."Dump";
   end if;
end loop;
return titles;
END;
$$ LANGUAGE plpgsql;
</code></pre>

<p>I am calling this function in java like</p>

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

<p>but i am getting below error in console</p>

<pre><code>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)
</code></pre>

<p>Then I removed callable statement &amp; tried with prepared statement still getting error</p>

<p>My prepared statement code is </p>

<pre><code>try (PreparedStatement stmt = backgroundobj.getDBConnection(prop).prepareStatement("select ThirdPartyDataParse()")) {
    stmt.execute();
}
</code></pre>

<p>exception is </p>

<pre><code>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)
</code></pre>