Starbuck wrote:
Starbuck wrote:
Can anyone see what is wrong here
CallableStatement cs = con.prepareCall("{ ? = call list_index () }");
cs.registerOutParameter(1, Types.OTHER);
cs.execute();
ResultSet rs = (ResultSet) cs.getObject(1);
while (rs.next())
{
//read the returned recordset }
When - ResultSet rs = (ResultSet) cs.getObject(1);
is executed the error is - "[B cannot be cast to java.sql.ResultSet"
The stored procedure being called is as follows, it works fine in c#
CREATE PROCEDURE list_index
AS
BEGIN
/* Procedure body */
SELECT name FROM listtypes where ctype = 'C' order by ndx
END
Thanks in advance chaps.
Its ok, silly me
//ResultSet rs = (ResultSet) cs.getObject(1);
ResultSet rs = cs.executeQuery();
Works fine now.
An SP can return:
- out parameters
- result sets
- return values
A long time ago I created the following to demo the
various options:
CREATE PROCEDURE TEST_MULTIOUT
@inarg INTEGER,
@outarg INTEGER OUTPUT
AS
SELECT @outarg = 123
SELECT * FROM T1
SELECT * FROM T1
RETURN -@inarg
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Types;
public class UseSP {
public static void main(String[] args) throws Exception {
Class.forName("com.sybase.jdbc2.jdbc.SybDriver");
Connection con =
DriverManager.getConnection("jdbc:sybase:Tds:arnepc2:5000", "sa", "");
con.setCatalog("Test");
CallableStatement cstmt = con.prepareCall("{? = CALL
TEST_MULTIOUT(?,?)}");
cstmt.registerOutParameter(1, Types.INTEGER);
cstmt.setInt(2, 5);
cstmt.registerOutParameter(3, Types.INTEGER);
cstmt.execute();
while(cstmt.getMoreResults()) {
ResultSet rs = cstmt.getResultSet();
while(rs.next()) {
System.out.println(rs.getInt(1) + " " + rs.getString(2));
}
}
System.out.println("return value = " + cstmt.getInt(1));
System.out.println("out parameter = " + cstmt.getInt(3));
cstmt.close();
con.close();
}
}
Arne
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!