Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2008
    Posts
    2

    Unanswered: Sybase Stored Procedure to return Result Set to a Java program

    Hi,
    I have a simple stored proc that queries a table.
    This stored proc is called from a Java class.
    But when I try to retrieve the ResultSet I get null ResultSet.

    Your help is gretly appreciated.


    Here is the code:

    CREATE PROCEDURE dbo.proc_test_page (
    @APPLICATION VARCHAR(10)
    )
    AS

    BEGIN

    SELECT SHRTNME_TYPE_ID FROM APPUSE_SHRTNMTYPE WHERE APPLICATION = @APPLICATION

    END

    -- Java Code
    CallableStatement cstmt =
    cdrDBMgr.getConnection().prepareCall("{call dbo.proc_test_page (?)}");

    cstmt.setString(1, "GLOBALBOOK");
    ResultSet rs =null;
    cstmt.execute();
    rs = (ResultSet)cstmt.getResultSet();

  2. #2
    Join Date
    Feb 2008
    Posts
    2
    Thank you. I have managed to get the solution.

  3. #3
    Join Date
    Feb 2008
    Posts
    1
    Hello,

    I am having a similar problem. Could you explain how you resolved this issue?

  4. #4
    Join Date
    Aug 2010
    Posts
    1

    re Sybase Stored Procedure to return Result Set to a Java program

    Quote Originally Posted by sclee View Post
    Hello,

    I am having a similar problem. Could you explain how you resolved this issue?
    I don't know what he did, but I had a similar very frustrating situation. I spent the better part of two days trying to figure this out.

    The problem is "Oracle thinking" where you need to use their own classes, etc. to do things. Sybase appears to be a lot easier. FYI, I am on an IBM WAS v.6.0 using RAD. Here's my code:

    import java.sql.*;
    import javax.sql.*;
    import javax.naming.*;
    import javax.util.*;

    Hashtable env = new Hashtable();
    DataSource ds = null;
    String SYBASE_DATA_SOURCE_NAME = "jdbc/{your J2EE connector URI}";

    try{
    InitialContext ctx = new InitialContext(env);
    ds = (DataSource) ctx.lookup(SYBASE_DATA_SOURCE_NAME);
    } catch (Exception e) { e.printStackTrace(); }
    }

    String sql = "{?=call some_scriptname(some_paramstring)}";

    Connection cn = ds.getConnection();
    CallableStatement cs = cn.prepareCall(sql);
    cs.prepareCall(sql);
    ResultSet rs = cs.executeQuery();

    if (rs!=null){
    while (rs.hasNext())
    {
    // do stuff
    }
    }

    Yes, it is THAT simple. I hope this helps someone else out there who is thrashing about making life harder than it needs to be.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •