???????????????????У?
????declare @myResult int
????exec getsum 100??@myResult output
????print @myResult
??????JAVA?е????
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);
//???洢????????????
c.registerOutParameter(2??java.sql.Types.INTEGER);
//???д洢????
c.execute();
//????洢????????????
System.out.println (c.getInt(2));
conn.close();
}
}
????2:????varchar
?????洢??????α?
??????洢?????д??α? ????α???????orderid
????create procedure CursorIntoProcedure
????@pname varchar(8000) output
????as
????--?????α?
????declare cur cursor for select orderid from orders
????--??????????????????α???
????declare @v varchar(5)
????--???α?
????open cur
????set @pname=''--??@pname???
????--????α???
????fetch next from cur into @v
????while @@fetch_status=0
????begin
????set @pname=@pname+';'+@v
????fetch next from cur into @v
????end
????print @pname
????--????α?
????close cur
????--?????α?
????deallocate cur
???????д洢?????
????exec CursorIntoProcedure ''
????JAVA?????
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 CursorIntoProcedure(?)}");
c.registerOutParameter(1??java.sql.Types.VARCHAR);
c.execute();
System.out.println (c.getString(1));
conn.close();
}
}
????C??????????洢????
?????洢?????
drop table ????????????
create table ????????????
(
StuID int primary key??
StuName varchar(10)??
StuAddress varchar(20)
)
insert into ???????????? values(1??'???'??'wuhan')
insert into ???????????? values(2??'???'??'wuhan')
create table ????????
(
StuID int??
Chinese int??
PyhSics int
foreign key(StuID) references ????????????(StuID)
on delete cascade
on update cascade
)
insert into ???????? values(1??99??100)
insert into ???????? values(2??99??100)
?????????洢?????
????create procedure delePro
????@StuID int
????as
????delete from ???????????? where StuID=@StuID
????--???????
????exec delePro 1 --???д洢????
????--?????洢????
????create procedure selePro
????as
????select * from ????????????
????--???????
????exec selePro --???д洢????
??????JAVA?е????
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 delePro(?)}");
c.setInt(1??1);
c.execute();
c=conn.prepareCall("{call selePro}");
ResultSet rs=c.executeQuery();
while(rs.next())
{
String Stu=rs.getString("StuID");
String name=rs.getString("StuName");
String add=rs.getString("StuAddress");
System.out.println ("???:"+" "+"????:"+" "+"???");
System.out.println (Stu+" "+name+" "+add);
}
c.close();
}
}