re_data = 1,然后结束循环 END REPEAT;
最后关闭游标 close my_cursor;
因为上面在定义游标时,指明了,没有数据时设置了 no_more_data = 1,所以这里使用 UNTIL no_more_data = 1 来退出repeat
?
2)判断相等是使用 = ,而不是 == ,赋值操作是使用 set var=xxx; :set fuben_times = total_level / 2;
?
?
1)hibernate调用存储过程:
?
/*
* 调用无参数的存储过程,传入存储过程名字
*/
public int callProcedure(final String procedureName)
{
int count = (Integer)this.getHibernateTemplate().execute(
new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException, SQLException {
String procedureSql = "{call "+ procedureName +"()}";
Query query = session.createSQLQuery(procedureSql);
Integer num = query.executeUpdate();
return num;
}
});
return count;
}
?
?
@Override
public Long loginAndRegByProcedure(String user_Pwd, String user_MobileCode, String user_RegIP){
Long userId = null;
HashMap paramMap = new HashMap();
paramMap.put("userId", userId);
paramMap.put("user_Pwd", user_Pwd);
paramMap.put("user_MobileCode", user_MobileCode);
paramMap.put("user_RegIP", user_RegIP);
this.getSqlMapClientTemplate().queryForObject("Users.loginAndRegByProcedure", paramMap);
return (Long)paramMap.get("userId");
}
?
对应的xml 文件配置:
?
{call loginandreg(?, ?, ?, ?)}
?
?
存储过程的参数的类型,是在xml文件中说明的。
?
3) JDBC 调用mysql 存储过程:
?
public Long loginAndRegByProcedure2(String user_Pwd, String user_MobileCode, String user_RegIP){
Connection conn = DbUtil.getConnection();
CallableStatement cstmt = conn.prepareCall("{call loginandreg(?, ?, ?, ?)}");
cstmt.setString(2, user_Pwd);
cstmt.setString(3, user_MobileCode);
cstmt.setString(4, user_RegIP);
cstmt.registerOutParameter(1, java.sql.Types.BIGINT);
cstmt.execute();
return cstmt.getLong(1);
}
?
输入参数:cstmt.setString(2, user_Pwd);
?
输出参数:cstmt.registerOutParameter(1, java.sql.Types.BIGINT);