此语句用于检查用户是否存在于数据库中。
public boolean isExisting(int userId) {
String sql = "{call isExistingUser(?)}";
Session session = null;
boolean isExisting = false;
try {
session = getSession();
SQLQuery query = session.createSQLQuery(sql);
query.setParameter(0, userId);
List<?> list = query.list();
isExisting = list.get(0) != null ? (Boolean) list.get(0) : false;
} finally {
if (session != null)
session.close();
}
return isExisting;
}
这是存储过程:
CREATE DEFINER = cbsadmin
@ %
程序isExistingUser
(IN userId int)
开始
SELECT USER_ID FROM USER_LOGIN_STATUS WHERE USER_ID = userId;
END