???????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 java.sql.*;
public class ProcedureTest
{
public static void main(String args[]) throws Exception
{
//????????
DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
//???????
Connection conn=DriverManager.getConnection("jdbc:odbc:mydata"??"sa"??"");
//?????洢????????
CallableStatement c=conn.prepareCall("{call getsum(?)}");
//???洢?????????????
c.setInt(1??100); //????????????????ó?100
//???д洢????
c.execute();
conn.close();
}
}
????B????????????
????1:????int
alter procedure getsum
@n int =0??
@result int output
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
set @result=@sum