1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| UserParaDao.java
* 判断用户名和密码是否匹配 * * @param userPara * @return * @throws Exception */ public boolean checkNameAndPsw(UserPara userPara) throws Exception { String sql = "SELECT PASSWORD FROM C_USER WHERE NAME=?\n"; ResultSet rs = DaoUtil.executeQuery(DaoTools.getConnName(), sql, new String[] { userPara.getName() }); if (rs != null) { while (rs.next()) { if (userPara.getPassword().equals(rs.getString("PASSWORD"))) { return true; } } } return false; }
* 判断用户是否存在 * * @param userName * @return * @throws Exception */ public boolean checkUser(String userName) throws Exception { String sql = "SELECT NAME FROM C_USER WHERE NAME=?\n"; ResultSet rs = DaoUtil.executeQuery(DaoTools.getConnName(), sql, new String[] { userName }); if (rs != null) { while (rs.next()) { return true; } } return false; }
* 根据用户名判断是否有过登录记录 */ public boolean checkLoginRecord(String userName) throws Exception { String sql = "SELECT COUNT(*) num FROM C_LOGIN_RECORD WHERE USERNAME=?\n "; ResultSet rs = DaoUtil.executeQuery(DaoTools.getConnName(), sql, new String[] { userName }); if (rs != null) { while (rs.next()) { if ("0".equals(rs.getString("num"))) { return false; } } } return true; }
* 删除用户的登录记录 * * @param userName * @throws Exception */ public void deleteLoginRecord(String userName) throws Exception { String sql = "DELETE FROM C_LOGIN_RECORD WHERE USERNAME=? \n"; DaoUtil.executeUpdate(DaoTools.getConnName(), sql, new String[] { userName }); }
* 获取用户最近的一条登录记录 * * @param userName * @return * @throws Exception */ public ResultSet getLatestLoginRecord(String userName) throws Exception { String sql = "SELECT USERNAME, LOCK_FLAG, FAILURE_NUM, LOGIN_DATE " + " FROM C_LOGIN_RECORD WHERE LOGIN_DATE=(SELECT MAX(LOGIN_DATE)" + "FROM C_LOGIN_RECORD WHERE USERNAME=? GROUP BY USERNAME)"; return DaoUtil.executeQuery(DaoTools.getConnName(), sql, new String[] { userName });
}
* 获取用户登录失败次数为2的登录登录时间 * @param userName * @return * @throws Exception */ public String getFaNum2Record(String userName) throws Exception { String sql = "SELECT USERNAME,LOGIN_DATE FROM C_LOGIN_RECORD " + " WHERE USERNAME=? AND FAILURE_NUM=2"; ResultSet rs = DaoUtil.executeQuery(DaoTools.getConnName(), sql, new String[] { userName }); if (rs != null) { while (rs.next()) { return rs.getString("LOGIN_DATE").replace("T", " "); } } return ""; }
* 插入登录记录 * @param userName * @param lockFlag * @param failureNum */ public void insertLoginRecord(String userName, String lockFlag, String failureNum) { List<String> list=new ArrayList<String>(); String sql="INSERT INTO C_LOGIN_RECORD(USERNAME,LOCK_FLAG,FAILURE_NUM," + "LOGIN_DATE) values(? ,? ,? , sysdate)"; list.add(userName); list.add(lockFlag); list.add(failureNum); DaoUtil.executeUpdate(DaoTools.getConnName(), sql, list.toArray()); }
|