jsp调用存储过程

来源:互联网 发布:视频网络直播所需设备 编辑:程序博客网 时间:2024/06/05 11:31

存储过程:

create proc logon
@worker_id int,
@password char(20)
as
select *
from workers
where worker_id=@worker_id
and password=@password
go

调用代码(返回结果集):

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
    String url="jdbc:sqlserver://localhost:1433;DatabaseName=Cinema_Ticketing";
    String user="sa";//数据库用户名
    String password="123456";//数据库密码
    conn=DriverManager.getConnection(url,user,password);
    //返回结果集存储过程
    CallableStatement   cstmt   =   conn.prepareCall   ("{call logon(?,?)}");
    cstmt.setInt(1, worker_id);
    cstmt.setString(2, pas);
    cstmt.executeQuery();
    rs=cstmt.getResultSet();//结果集