存储过程:
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();//结果集