473,395 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

retrieve an output parameter in stored procedure from java application

in my java application I've made a call to this stored procedure

CREATE procedure pruebaICM
@pANI varchar(20),
@pTABLA varchar(20),
@pInsert varchar(500),
@pUpdate varchar(1000),
@pFLAG varchar(1),
@pResultado int OUTPUT

as
begin

DECLARE @ani varchar(20)
declare @cliente int
DECLARE @sentencia nvarchar(1000)
DECLARE @tabla nvarchar(20)
DECLARE @sentencia_where nvarchar(50)
DECLARE @sql nvarchar(1050)
SET NOCOUNT ON
set @tabla = @pTABLA
set @ani = @pANI
SELECT @sql= N'select @cliente=count(ani) from '+ @tabla + N' where
ani = ' + @ani
exec sp_executesql @sql, N'@Cliente INT OUTPUT', @Cliente OUTPUT
SELECT @Cliente
if (@pFLAG = 'A') or (@pFLAG = 'Actualizar') or (@pFLAG = 'I')
begin
if (@cliente = 0)
begin
set @sentencia = N'insert into ' +
@pTABLA + N' values (' + @pInsert + N')'
EXEC sp_executesql @sentencia
set @pResultado = 1
SELECT @pResultado
return @pResultado
end

if (@cliente = 1)
begin
set @sentencia = N'update ' + @pTABLA +
N' set ' + @pUpdate
set @sentencia_where = N' where ANI =
' + @pANI
set @sql = @sentencia +
@sentencia_where
EXEC sp_executesql @sql
set @pResultado = 2
SELECT @pResultado
return @pResultado
end

end
else if (@pFLAG = 'B') or (@pFLAG = 'Borrar')
begin

if (@cliente = 0)
begin
set @pResultado = 0
SELECT @pResultado
return @pResultado
end
else if (@cliente = 1)
begin
set @sentencia = N'delete from '+
@pTABLA + N' where ANI = ' + @pANI
EXEC sp_executesql @sentencia
set @pResultado = 3
SELECT @pResultado
return @pResultado
end
end
EXEC sp_cursorclose
end

My problem is that the ouutput param @pResultado haven't got any value
and don't return anything to the java application. How can I fix this
problem?

Thanka very much for helping me!!!!
Jul 20 '05 #1
2 10358
be**********@yahoo.es (Begoņa) wrote in message news:<c0**************************@posting.google. com>...
in my java application I've made a call to this stored procedure

CREATE procedure pruebaICM
@pANI varchar(20),
@pTABLA varchar(20),
@pInsert varchar(500),
@pUpdate varchar(1000),
@pFLAG varchar(1),
@pResultado int OUTPUT

as
begin

DECLARE @ani varchar(20)
declare @cliente int
DECLARE @sentencia nvarchar(1000)
DECLARE @tabla nvarchar(20)
DECLARE @sentencia_where nvarchar(50)
DECLARE @sql nvarchar(1050)
SET NOCOUNT ON
set @tabla = @pTABLA
set @ani = @pANI
SELECT @sql= N'select @cliente=count(ani) from '+ @tabla + N' where
ani = ' + @ani
exec sp_executesql @sql, N'@Cliente INT OUTPUT', @Cliente OUTPUT
SELECT @Cliente
if (@pFLAG = 'A') or (@pFLAG = 'Actualizar') or (@pFLAG = 'I')
begin
if (@cliente = 0)
begin
set @sentencia = N'insert into ' +
@pTABLA + N' values (' + @pInsert + N')'
EXEC sp_executesql @sentencia
set @pResultado = 1
SELECT @pResultado
return @pResultado
end

if (@cliente = 1)
begin
set @sentencia = N'update ' + @pTABLA +
N' set ' + @pUpdate
set @sentencia_where = N' where ANI =
' + @pANI
set @sql = @sentencia +
@sentencia_where
EXEC sp_executesql @sql
set @pResultado = 2
SELECT @pResultado
return @pResultado
end

end
else if (@pFLAG = 'B') or (@pFLAG = 'Borrar')
begin

if (@cliente = 0)
begin
set @pResultado = 0
SELECT @pResultado
return @pResultado
end
else if (@cliente = 1)
begin
set @sentencia = N'delete from '+
@pTABLA + N' where ANI = ' + @pANI
EXEC sp_executesql @sentencia
set @pResultado = 3
SELECT @pResultado
return @pResultado
end
end
EXEC sp_cursorclose
end

My problem is that the ouutput param @pResultado haven't got any value
and don't return anything to the java application. How can I fix this
problem?

Thanka very much for helping me!!!!


You can try a couple of things to identify the problem. First, you can
use SELECT @sentencia and SELECT @sql in the procedure to make sure
that you are executing the code that you think you're executing.
Second, use the stored procedure debugger to check that the procedure
is following the logic that you want it to - the debugger will also
display the value of @pResultado, so you should be able to see why it
isn't being assigned a value.

Simon
Jul 20 '05 #2
If I execute this stored procedure inside query analyzer, it works
well; i see the value of @pResultado due to command "select
@pResultado"
and it's OK but the problem remainds when i try to retrieve this param
from my java application. I change de type of this param (@pResultado)
to varchar(1) and then i have the command System.out.print in java
application but the value es "" 8no value return).
Any idea???
Thanks very much for your help
sq*@hayes.ch (Simon Hayes) wrote in message news:<60**************************@posting.google. com>...
be**********@yahoo.es (Begoņa) wrote in message news:<c0**************************@posting.google. com>...
in my java application I've made a call to this stored procedure

CREATE procedure pruebaICM
@pANI varchar(20),
@pTABLA varchar(20),
@pInsert varchar(500),
@pUpdate varchar(1000),
@pFLAG varchar(1),
@pResultado int OUTPUT

as
begin

DECLARE @ani varchar(20)
declare @cliente int
DECLARE @sentencia nvarchar(1000)
DECLARE @tabla nvarchar(20)
DECLARE @sentencia_where nvarchar(50)
DECLARE @sql nvarchar(1050)
SET NOCOUNT ON
set @tabla = @pTABLA
set @ani = @pANI
SELECT @sql= N'select @cliente=count(ani) from '+ @tabla + N' where
ani = ' + @ani
exec sp_executesql @sql, N'@Cliente INT OUTPUT', @Cliente OUTPUT
SELECT @Cliente
if (@pFLAG = 'A') or (@pFLAG = 'Actualizar') or (@pFLAG = 'I')
begin
if (@cliente = 0)
begin
set @sentencia = N'insert into ' +
@pTABLA + N' values (' + @pInsert + N')'
EXEC sp_executesql @sentencia
set @pResultado = 1
SELECT @pResultado
return @pResultado
end

if (@cliente = 1)
begin
set @sentencia = N'update ' + @pTABLA +
N' set ' + @pUpdate
set @sentencia_where = N' where ANI =
' + @pANI
set @sql = @sentencia +
@sentencia_where
EXEC sp_executesql @sql
set @pResultado = 2
SELECT @pResultado
return @pResultado
end

end
else if (@pFLAG = 'B') or (@pFLAG = 'Borrar')
begin

if (@cliente = 0)
begin
set @pResultado = 0
SELECT @pResultado
return @pResultado
end
else if (@cliente = 1)
begin
set @sentencia = N'delete from '+
@pTABLA + N' where ANI = ' + @pANI
EXEC sp_executesql @sentencia
set @pResultado = 3
SELECT @pResultado
return @pResultado
end
end
EXEC sp_cursorclose
end

My problem is that the ouutput param @pResultado haven't got any value
and don't return anything to the java application. How can I fix this
problem?

Thanka very much for helping me!!!!


You can try a couple of things to identify the problem. First, you can
use SELECT @sentencia and SELECT @sql in the procedure to make sure
that you are executing the code that you think you're executing.
Second, use the stored procedure debugger to check that the procedure
is following the logic that you want it to - the debugger will also
display the value of @pResultado, so you should be able to see why it
isn't being assigned a value.

Simon

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Yusuf INCEKARA | last post by:
I have a stored procedure : CREATE PROCEDURE STP_GETSTORELIST @RETCUR CURSOR VARYING OUTPUT AS set @RETCUR = CURSOR FORWARD_ONLY STATIC FOR SELECT ID,STORE_NAME FROM T_INF_STORE ORDER BY...
8
by: Christopher Weaver | last post by:
I'm having trouble accessing the value of an output parameter of a stored procedure. The SP looks like this: SET TERM ^ ; CREATE PROCEDURE SP_NEW_TASK RETURNS ( "uidTask" INTEGER) AS begin
3
by: Hewit | last post by:
I have a stored procedure which returns records and output parameters(SQL2K). How to call this stored procedure using ADO.Net so that I can use both results in my application. I have .Net...
5
by: MS | last post by:
Here's my simple stored procedure: ALTER PROCEDURE GetMemberIDByEmail @Email EmailAddress, @ID int OUTPUT AS SELECT @ID = ID FROM tbl_Member WHERE Email=@Email RETURN
4
by: Mr Not So Know It All | last post by:
im new to SQL Server and ASP.Net. Here's my problem. I have this SQL Server stored procedure with an input parameter and output parameter CREATE PROCEDURE . @in_rc varchar(8) @out_eList...
0
by: r1 | last post by:
I am relatively inexperienced in using delegates and asynchronous methods. I read several articles, and then I developed my own code with a mission to improve the performance. Wow! I cannot...
4
by: Clint Pidlubny | last post by:
Hello, I'm using ASP.Net 2.0 and the Jan 2006 Enterprise Library. What I'm doing is passing an ArrayList into a stroed procedure to do an Insert. Here's some code: Dim params as New...
7
by: ashtek | last post by:
Hi, I have a generic function that executes a stored procedure & returns a data table. Code: === public static DataTable ExecuteStoredProcedure(string strProc,SqlParameter paramArray) {...
0
by: Sudarsana | last post by:
How to retrieve output parameter value in ASp from Stored Procedure
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.