delimiter $$
drop procedure if exists verify $$
/* 两个输入 loginId,登录ID,psw,登录密码 */
create procedure verify (
in loginId varchar(99),
in psw varchar(99)
)
begin
declare tmppsw varchar(99) default "";
select * from baseuser where baseuser.loginId = loginId;
if psw = tmppsw
then select * from baseuser where baseuser.loginId = loginId;
end if;
end $$
delimiter ;
2.获取一个存储过程:(返回值是一个CallableStatement类型的对象)
/**
* call a procedure
*
* @param procedureName
* @param argsNumber
* : number of parameters
* @return CallableStatement
*/
public CallableStatement getProcedureStmt(String procedureName,
int argsNumber, Connection con) {
CallableStatement stmt = null;
StringBuilder builder = new StringBuilder();
builder.append("{call " + procedureName + " (");
for (int i = 0; i < argsNumber; i++) {
builder.append(i == argsNumber - 1 ? "?)}" : "?,");
}
System.out.println(builder.toString());
try {
stmt = con.prepareCall(builder.toString());
} catch (SQLException e) {
e.printStackTrace();
}
return stmt;
}