Java, Sybase and CallableStatement
- From: edouard.briere@xxxxxxxxx
- Date: 28 Jun 2006 06:39:56 -0700
Hi everybody,
I've got a problem in calling a stored procedure with a
CallableStatement in JAVA.
So I've got a stocked procedure on a Sybase database. Here is the code:
create proc ps_part_composite_firme
(@CodFirme varchar(50) = 'F12', @IdLangue int = 2)
as
begin
if (@IdLangue = 1)
begin
SELECT COD_COMP AS CODE_COMPOSITE, LIB_COMP AS LIB_COMPOSITE,
convert(char(8), DAT_OUV, 112) AS DATE_OUV,
convert(char(8), DAT_CLO, 112) AS DATE_CLO
FROM E_COMPOSITE
WHERE COD_FIRM = @CodFirme
ORDER BY LIB_COMP
end
else
begin
SELECT COD_COMP AS CODE_COMPOSITE, LIB_REPORT AS LIB_COMPOSITE,
convert(char(8), DAT_OUV, 112) AS DATE_OUV,
convert(char(8), DAT_CLO, 112) AS DATE_CLO
FROM E_COMPOSITE
WHERE COD_FIRM = @CodFirme
ORDER BY LIB_REPORT
end
end
go
--
Here are some lines of my Java method to call the stocked procedure:
String query = "{call ps_part_composite_firme [(?, ?)]}";
SybCallableStatement call =
(SybCallableStatement)this.conn.prepareCall(query);
call.setString(1,"F11");
call.setInt(2,1);
SybCursorResultSet syb_rs = (SybCursorResultSet)call.executeQuery();
[the connection on the database has been done above, works just fine (I
tryed some basic queries) and is not displayed here]
When executing the code, I have this error : There is no host variable
corresponding to the one specified by the PARAM datastream. This means
that this variable '' was not used in the preceding DECLARE CURSOR or
SQL command.
It seems the error is situated in the call.setString and/or call.setInt
instruction.
So I changed it for:
call.setString("CodFirme","F11");
call.setInt("IdLangue",1);
But now I've the error: There is no host variable corresponding to the
one specified by the PARAM datastream. This means that this variable
'CodFirme' was not used in the preceding DECLARE CURSOR or SQL command.
Does anyone have an idea?
Thanks!
Edouard Brière
.
- Follow-Ups:
- Re: Java, Sybase and CallableStatement
- From: Robert Klemme
- Re: Java, Sybase and CallableStatement
- Prev by Date: DB2 "Pasword expired" and "pasword soon to expire" detection from java
- Next by Date: Re: Java, Sybase and CallableStatement
- Previous by thread: DB2 "Pasword expired" and "pasword soon to expire" detection from java
- Next by thread: Re: Java, Sybase and CallableStatement
- Index(es):