Evaluate Sybase return code


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Evaluate Sybase return code

  1. #1
    Join Date
    Jan 2005
    Location
    London
    Posts
    10

    Evaluate Sybase return code

    I am sure I have missed something very easy here.

    I have a sybase stored proc which wants to raise a warning by returning a return code other than 0.

    So at the end of the proc under certain scenarios I want to do either

    return 10001
    return 10002
    etc...

    How do I evaluate this in Java?

    I am doing the following:

    CallableStatement cstmt = null;
    Connection conn = null;
    try
    {
    conn = getConnection();
    cstmt = conn.prepareStatement("{call myproc ?});
    cstmt.setint(1,'anything');
    int j = cstmt.executeUpdate();
    log.info("j="+j);
    }
    catch (SQLExceptyiopn e)
    {
    log.error("exception of "+e.getMessage);
    e.printStackTrace();
    }
    finally
    {
    DBUtils.freeThings(conn,cstmt,null);
    }


    After running this the return code I always get is 1. I have tried a number of other things but have made no ground - any ideas?

    Thanks in advance

    Matt

  2. #2
    Join Date
    Dec 2003
    Location
    tx/us
    Posts
    131
    Maybe you want to do a query rather than an update. Updates return the number of rows changed, queries return values in result sets, in this case one row with one column.

  3. #3
    Join Date
    Jan 2005
    Location
    London
    Posts
    10
    Unfortunately the proc is doing a number of updates / inserts etc ad a executeQuery will not run as there is no resultset.

    The only way I can get it to do this is to change the proc to do the following :


    select @returnCode
    return

    to obtain a resultset but if i was to do this it would require changes in legacy systems using this proc. The final line of the proc currently does this

    return @returnCode

    It is the returnCode I need to get hold of but like you say the executeUpdate is returning the row count.

    Thanks anyway

    Matt

  4. #4
    Join Date
    Jan 2005
    Location
    London
    Posts
    10
    I have managed to do this if anyone needs to do it by setting the sql statement for a preparedstatement as follows:

    String sql = "declare @a int exec @a=myproc ?,?,? select @a"
    Then by doing execuequery into a resultset object @a is retrieved by rs.getint(1)

    M

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center