public static void logAccess(AccessLog objAL) { PreparedStatement ps = null; String sInsert = "INSERT INTO AccessLogs (accessid, userid, accesstime) VALUES (?, ?, ?)"; Connection ad_conn = MedwanQuery.getInstance().getAdminConnection(); try { ps = ad_conn.prepareStatement(sInsert); ps.setInt(1, MedwanQuery.getInstance().getOpenclinicCounter("AccessLogs")); ps.setInt(2, objAL.getUserid()); ps.setTimestamp(3, objAL.getAccesstime()); ps.execute(); ps.close(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (ps != null) ps.close(); ad_conn.close(); } catch (Exception e) { e.printStackTrace(); } } }
public static Vector searchAccessLogs(String sFindBegin, String sFindEnd) { PreparedStatement ps = null; ResultSet rs = null; Vector vAL = new Vector(); String sSelect; String sSelect1 = " SELECT a.accessid, a.accesstime, b.lastname, b.firstname FROM AccessLogs a, Users u, Admin b WHERE " + " a.accesstime BETWEEN ? AND ? AND u.userid = a.userid AND b.personid = u.personid " + " ORDER BY a.accesstime, b.searchname "; String sSelect2 = " SELECT a.accessid, a.accesstime, b.lastname, b.firstname FROM AccessLogs a, Users u, Admin b WHERE " + " a.accesstime >= ? AND u.userid = a.userid AND b.personid = u.personid " + " ORDER BY a.accesstime, b.searchname "; String sSelect3 = " SELECT a.accessid, a.accesstime, b.lastname, b.firstname FROM AccessLogs a, Users u, Admin b WHERE " + " a.accesstime <= ? AND u.userid = a.userid AND b.personid = u.personid " + " ORDER BY a.accesstime, b.searchname "; Connection ad_conn = MedwanQuery.getInstance().getAdminConnection(); try { if ((sFindBegin.trim().length() > 0) && (sFindEnd.trim().length() > 0)) { sSelect = sSelect1; ps = ad_conn.prepareStatement(sSelect); ps.setDate(1, ScreenHelper.getSQLDate(sFindBegin)); ps.setDate(2, ScreenHelper.getSQLDate(ScreenHelper.getDateAdd(sFindEnd, "1"))); } else if (sFindBegin.trim().length() > 0) { sSelect = sSelect2; ps = ad_conn.prepareStatement(sSelect); ps.setDate(1, ScreenHelper.getSQLDate(sFindBegin)); } else if (sFindEnd.trim().length() > 0) { sSelect = sSelect3; ps = ad_conn.prepareStatement(sSelect); ps.setDate(1, ScreenHelper.getSQLDate(ScreenHelper.getDateAdd(sFindEnd, "1"))); } rs = ps.executeQuery(); AccessLog objAL; while (rs.next()) { objAL = new AccessLog(); objAL.setAccessid(rs.getInt("accessid")); objAL.setLastname(ScreenHelper.checkString(rs.getString("lastname"))); objAL.setFirstname(ScreenHelper.checkString(rs.getString("firstname"))); objAL.setAccesstime(rs.getTimestamp("accesstime")); vAL.addElement(objAL); } rs.close(); ps.close(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (rs != null) rs.close(); if (ps != null) ps.close(); ad_conn.close(); } catch (Exception e) { e.printStackTrace(); } } return vAL; }