Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Interfaces Jdbc > CallableStateme...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 6 Topic 1915 of 1997
Post > Topic >>

CallableStatement and getUpdateCount

by sam@[EMAIL PROTECTED] (Sam Lawrence) Mar 31, 2008 at 04:29 PM

Hi,

I have a query about using CallableStatement with functions that return 
a SETOF. I know the "Calling Stored Functions" do***entation says use a 
Statement or a PreparedStatement - I'm in the process of ****ting over a 
database and would like to leave my calling code the same - that means 
CallableStatement (more in a moment).

First, an example. A simple function (I know the SETOF is redundant in 
this example, normally it wouldn't be) -

    CREATE OR REPLACE FUNCTION cstest()
    RETURNS SETOF integer AS
    $$
        SELECT 1;
    $$
    LANGUAGE 'sql' VOLATILE;

The calling code -

    Class.forName("org.postgresql.Driver");
    Connection con = DriverManager.getConnection("...");
   
    CallableStatement cs = con.prepareCall("{call cstest()}");
    cs.execute();
   
    System.out.println("update count - should be -1? " + 
cs.getUpdateCount());
   
    ResultSet rs = cs.getResultSet();
    while(rs.next())
    {
        System.out.println(rs.getInt(1));
    }
    rs.close();
    cs.close();
    con.close();

The code works fine and returns the record correctly. My problem is the 
getUpdateCount after the execute - from the java.sql.Statement 
do***entation "if the result is a ResultSet object or there are no more 
results, -1 is returned". It actually comes back as 1. Is this a bug or 
have I missed something?

I found this problem via Spring's 
org.springframework.jdbc.object.StoredProcedure class - it doesn't find 
any ResultSets because it relies on the value of getUpdateCount.

I'm running PostgreSQL 8.3.0 with postgresql-8.3-603.jdbc4.

Thanks in advance.

Sam.



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
 




 6 Posts in Topic:
CallableStatement and getUpdateCount
sam@[EMAIL PROTECTED] (S  2008-03-31 16:29:11 
Re: CallableStatement and getUpdateCount
laurenz.albe@[EMAIL PROTE  2008-04-01 10:03:34 
Re: CallableStatement and getUpdateCount
books@[EMAIL PROTECTED]   2008-04-01 13:28:45 
Re: CallableStatement and getUpdateCount
laurenz.albe@[EMAIL PROTE  2008-04-02 10:25:30 
Re: CallableStatement and getUpdateCount
sam@[EMAIL PROTECTED] (S  2008-04-02 18:52:16 
Re: CallableStatement and getUpdateCount
laurenz.albe@[EMAIL PROTE  2008-04-03 10:25:28 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Thu Jul 24 1:56:00 CDT 2008.