java 调用存储过程 怎么用?

来源:百度知道 编辑:UC知道 时间:2024/05/07 13:57:21
Create PROCEDURE proc_ViewSendinfo @bid int

as
declare @EndDate int

set @EndDate=0
while (@EndDate<7)
begin

select count(*) from sendinfo left join staffinfo on(sendinfo.sid = staffinfo.sid)
where convert(varchar(20),sendinfo.sdata,101) = convert(varchar(20),dateadd(day,@EndDate,getdate()),101)
and staffinfo.bid = @bid and sendinfo.stime = 1
group by sendinfo.stime,staffinfo.bid
set @EndDate = @EndDate +1

end

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

我的这个存储过程 怎么调用 它查出来的是7条纪录!!!!!

我的方法
Vector vec = new Vector();
// 定义一个 字符串连接
StringBuffer sb = null;
//定义一个数据库连接对象
BaseConnection db = null;
db = new BaseConnection();
sb = new StringBuffer();
ResultSet rs = null;
sb.append("exec proc_ViewSendinfo ");
sb.append(""+branch.getBid()+"");

给你个我以前做的例子吧
public void proselect(){
PreparedStatement pstmt=null;
Connection conn=null;
ResultSet rs=null;
conn=com.opendb.OpenDB.conn();//这个只是建立个连接
try {
pstmt = conn.prepareCall("call sel");//调用存储过程sel ,sel代码为select * from test
rs=pstmt.executeQuery();
System.out.println(rs);
while(rs.next()){
System.out.print(rs.getInt(2));
System.out.println(rs.getString(1));
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}

}

pstmt = conn.prepareCall("call yourProcedureName");//调用存储过程yourProcedureName
rs=pstmt.executeQuery();

之后就不用多说了