Search Postgresql Archives

Re: Function with RETURN TYPE RECORD Called From JAVA

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Sun, 16 May 2004, Sumita Biswas wrote:

> Hi All,
> 
> I have a Function that returns a variable of Type RECORD.

No you don't.  You have a function that returns setof 
Proc_ConferenceSummary which is different than returning record or setof 
record.  There is a difference in calling conventions in that you must 
specify the output type of a function that returns record when calling it.  
This difference is not essential to the problem at hand though.


> When I execute this Function from JAVA and try to get the Return
> Variable in a ResultSet object I get the following Error:
> 
> Exception in thread "main" java.lang.ClassCastException
>         at com.cisco.ccm.car.general.Test.testStoredProc(Test.java:119)
> 
> 	objCallStmt = objCARConn.prepareCall("{ ? = call
> Proc_ConferenceSummary(?,?,?,?,?) }");
> 	objCallStmt.registerOutParameter(1, 12);
> 
> 	objCallStmt.setString(2,"3/5/2004");
> 	objCallStmt.setString(3,"5/5/2004");
> 	objCallStmt.setInt(4,1);
> 	objCallStmt.setInt(5,1);
> 	objCallStmt.setInt(6,5001);
> 	objCallStmt.execute();
> 	ResultSet rs = (ResultSet)objCallStmt.getObject(1);//THIS IS

This only works for functions that return refcursor.  Instead of using a 
CallableStatement you should just use a regular PreparedStatement and a 
SELECT query:

Connection conn = DriverManager.getConnection(...);
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM 
myfunction(?,?)");
pstmt.setInt(1,12);
pstmt.setString(2,"abc");
ResultSet rs = pstmt.executeQuery();

Kris Jurka

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux