Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / June 2006

Tip: Looking for answers? Try searching our database.

Java, Sybase and CallableStatement

Thread view: 
edouard.briere@gmail.com - 28 Jun 2006 14:39 GMT
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
Robert Klemme - 28 Jun 2006 15:58 GMT
> 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:

[...]

> Here are some lines of my Java method to call the stocked procedure:
>
> String query = "{call ps_part_composite_firme [(?, ?)]}";

I think you have to remove the square brackets. See
http://java.sun.com/j2se/1.4.2/docs/guide/jdbc/getstart/statement.html#999472

(Square brackets on that page serve to indicate () is optional.)

Kind regards

    robert


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.