| From: | Kris Jurka <books(at)ejurka(dot)com> | 
|---|---|
| To: | Sumita Biswas <sbiswas(at)cisco(dot)com> | 
| Cc: | pgsql-general(at)postgresql(dot)org, 'Tom Lane' <tgl(at)sss(dot)pgh(dot)pa(dot)us>, 'Richard Huxton' <dev(at)archonet(dot)com> | 
| Subject: | Re: Function with RETURN TYPE RECORD Called From JAVA | 
| Date: | 2004-05-17 03:58:08 | 
| Message-ID: | Pine.BSO.4.56.0405162251020.24910@leary.csoft.net | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | David Teran | 2004-05-17 06:25:59 | Re: RTRIM always used with JDBC? | 
| Previous Message | Sumita Biswas | 2004-05-17 02:10:07 | Function with RETURN TYPE RECORD Called From JAVA |