?? authutil.java
字號:
/**
*
*/
package com.air.backend.util;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.air.exceptions.AirException;
import com.air.model.LoginUser;
import com.air.persistence.DataSrcUtil;
import com.air.persistence.IsqlDataSource;
import com.air.util.ValHelper;
/**
* @author jelly_yang
*
*/
public final class AuthUtil {
private static Log log = LogFactory.getLog(AuthUtil.class);
private AuthUtil(){
}
private static class AuthUtilHolder{
static final AuthUtil authUtil = new AuthUtil();
}
public static AuthUtil getInstance(){
return AuthUtilHolder.authUtil;
}
public LoginUser login(String loginname,String pwd) throws AirException
{
LoginUser user = null;
Map<String, String> result = new HashMap<String, String>();
String sSql = "select username,pwd,name,sex,certification_type,certification_code,question,answer from users where username='"+loginname+"' and pwd='"+pwd+"'";
IsqlDataSource src = DataSrcUtil.getInstance().getDataSource();
Connection conn = null;
try
{
conn = src.getConnection();
result = src.retrieveSingleRow(conn, sSql);
}
catch(SQLException se)
{
se.printStackTrace();
log.error("login() caught SQLException: " + se);
}
catch(Exception ex)
{
ex.printStackTrace();
log.error("login() caught Exception: " + ex);
}
finally
{
src.closeConn(conn);
}
if(!result.isEmpty())
{
String username = ValHelper.getInstance().getValue(result, "username");
String password = ValHelper.getInstance().getValue(result, "pwd");
String name = ValHelper.getInstance().getValue(result, "name");
String sex = ValHelper.getInstance().getValue(result, "sex");
String certificationType = ValHelper.getInstance().getValue(result, "certification_type");
String certificationCode = ValHelper.getInstance().getValue(result, "certification_code");
String question = ValHelper.getInstance().getValue(result, "question");
String answer = ValHelper.getInstance().getValue(result, "answer");
user = new LoginUser(username, password,name,sex,certificationType,certificationCode,question,answer);
}
return user;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -