2024年4月11日发(作者:)

Java中对存储过程的调用

一:Java如何实现对存储过程的调用:

A:不带输出参数的

---------------不带输出参数的----------------------------------

create procedure getsum

@n int =0<--此处为参数-->

as

declare @sum int<--定义变量-->

declare @i int

set @sum=0

set @i=0

while @i<=@n begin

set @sum=@sum+@i

set @i=@i+1

end

print 'the sum is '+ltrim(rtrim(str(@sum)))

--------------在SQL中执行:--------------------

exec getsum 100

------------在JAVA中调用:---------------------

JAVA可以调用 但是在JAVA程序却不能去显示该存储过程的结果 因为上面的存储

过程的参数类型int 传递方式是in(按值)方式

import .*;

public class ProcedureTest

{

public static void main(String args[]) throws Exception

{