📄 log_loginbean.java
字号:
package com.vere.log.bean; import java.sql.*; import java.util.*; import com.vere.db.*; import com.vere.log.item.*; public class Log_loginBean { private ResultSet rs=null; private int keyId; private int totalRecord; private Access access = null; public Log_loginBean() { try { access=new Access(); } catch(Exception e) { System.out.println(e.toString()); } } /** * @author Administrator * @param * @return ArrayList:Log_loginItem * @see */ public List find(){ ArrayList list=new ArrayList(); try { String sql="select * from "+T.LOG_LOGIN; rs = executeQuery(sql); while(rs.next()){ Log_loginItem item=new Log_loginItem(); item.setId(rs.getString("id")); item.setLogin_username(rs.getString("login_username")); item.setLogin_name(rs.getString("login_name")); item.setIp(rs.getString("ip")); item.setLogintime(rs.getString("logintime")); item.setLogin_area(rs.getString("login_area")); item.setLogin_area_id(rs.getString("login_area_id")); item.setLogin_area_nodepath(rs.getString("login_area_nodepath")); list.add(item); } }catch(SQLException e){ System.out.print(e.toString()); } finally{ DBclose(); } return list; } /** * @author Administrator * @param * @return ArrayList * @see */ public List findByIds(String ids){ ArrayList list=new ArrayList(); try { String sql="select * from "+T.LOG_LOGIN+" where id in ("+ids+")"; rs = executeQuery(sql); while(rs.next()){ Log_loginItem item=new Log_loginItem(); item.setId(rs.getString("id")); item.setLogin_username(rs.getString("login_username")); item.setLogin_name(rs.getString("login_name")); item.setIp(rs.getString("ip")); item.setLogintime(rs.getString("logintime")); item.setLogin_area(rs.getString("login_area")); item.setLogin_area_id(rs.getString("login_area_id")); item.setLogin_area_nodepath(rs.getString("login_area_nodepath")); list.add(item); } }catch(SQLException e){ System.out.print(e.toString()); } finally{ DBclose(); } return list; } /** * @author Administrator * @param id * @return Log_loginItem * @see */ public Log_loginItem find(String id){ try { String sql="select "+T.LOG_LOGIN+".* from "+T.LOG_LOGIN+" where "+T.LOG_LOGIN+".id="+id; rs = executeQuery(sql); Log_loginItem item=new Log_loginItem(); if(rs.next()){ item.setId(rs.getString("id")); item.setLogin_username(rs.getString("login_username")); item.setLogin_name(rs.getString("login_name")); item.setIp(rs.getString("ip")); item.setLogintime(rs.getString("logintime")); item.setLogin_area(rs.getString("login_area")); item.setLogin_area_id(rs.getString("login_area_id")); item.setLogin_area_nodepath(rs.getString("login_area_nodepath")); } return item; }catch(SQLException e){ System.out.print(e.toString()); return null; } finally{ DBclose(); } } /** * @author Administrator * @param aItem,page,pageSize * @return ArrayList * @see */ public List find(Log_loginItem aItem,int page,int pageSize){ int nextPageSize=pageSize*(page-1); ArrayList list=new ArrayList(); try { boolean b=false; StringBuffer filter=new StringBuffer(); String fvalue=null; fvalue=aItem.getLogin_username(); if(fvalue!=null && fvalue.length()>0) { if(b) filter.append(" and"); filter.append(" "+T.LOG_LOGIN+".login_username like '%"+fvalue+"%' "); b=true; } fvalue=aItem.getLogin_name(); if(fvalue!=null && fvalue.length()>0) { if(b) filter.append(" and"); filter.append(" "+T.LOG_LOGIN+".login_name like '%"+fvalue+"%' "); b=true; } fvalue=aItem.getIp(); if(fvalue!=null && fvalue.length()>0) { if(b) filter.append(" and"); filter.append(" "+T.LOG_LOGIN+".ip like '%"+fvalue+"%' "); b=true; } fvalue=aItem.getLogintime(); if(fvalue!=null && fvalue.length()>0) { if(b) filter.append(" and"); filter.append(" DATEDIFF(day,"+T.LOG_LOGIN+".logintime,'"+fvalue+"')=0 "); b=true; } fvalue=aItem.getLogin_area(); if(fvalue!=null && fvalue.length()>0) { if(b) filter.append(" and"); filter.append(" "+T.LOG_LOGIN+".login_area like '%"+fvalue+"%' "); b=true; } fvalue=aItem.getLogin_area_id(); if(fvalue!=null && fvalue.length()>0) { if(b) filter.append(" and"); filter.append(" "+T.LOG_LOGIN+".login_area_id ="+fvalue+" "); b=true; } fvalue=aItem.getLogin_area_nodepath(); if(fvalue!=null && fvalue.length()>0) { if(b) filter.append(" and"); filter.append(" ','+"+T.LOG_LOGIN+".login_area_nodepath+',' like ',%"+fvalue+"%,' "); b=true; } StringBuffer sql=new StringBuffer(); sql.append(" select top "+pageSize+" "+T.LOG_LOGIN+".* from "+T.LOG_LOGIN+" where "); if(b) { sql.append(" "+filter.toString()+" and "); } sql.append(" ("+T.LOG_LOGIN+".id not in (SELECT TOP "+Integer.toString(nextPageSize)+" "+T.LOG_LOGIN+".id from "+T.LOG_LOGIN+" "); if(b) { sql.append(" where "+filter.toString()+" "); } sql.append(" order by "+T.LOG_LOGIN+".id desc )) order by "+T.LOG_LOGIN+".id desc "); rs = executeQuery(sql.toString()); while(rs.next()){ Log_loginItem item=new Log_loginItem(); item.setId(rs.getString("id")); item.setLogin_username(rs.getString("login_username")); item.setLogin_name(rs.getString("login_name")); item.setIp(rs.getString("ip")); item.setLogintime(rs.getString("logintime")); item.setLogin_area(rs.getString("login_area")); item.setLogin_area_id(rs.getString("login_area_id")); item.setLogin_area_nodepath(rs.getString("login_area_nodepath")); list.add(item); } String sql1="select count(*) as total from "+T.LOG_LOGIN+" "; if(b) sql1+=" where "+filter.toString(); rs = executeQuery(sql1); if(rs.next()){ totalRecord=rs.getInt("total"); } }catch(SQLException e){ System.out.print(e.toString()); } finally{ DBclose(); } return list; } /** * @author Administrator * @param * @return KeyId insert id * @see */ public int getKey(){ return keyId; } /** * @author Administrator * @param * @return (totalRecord) * @see get insert id */ public int getTotalRecord(){ return totalRecord; } /** * @author Administrator * @param item :Log_loginItem * @return boolean * @see */ public boolean addItem(Log_loginItem item){ try{ String sql="insert into "+T.LOG_LOGIN+"("+ "login_username,"+ "login_name,"+ "ip,"+ "logintime,"+ "login_area,"+ "login_area_id,"+ "login_area_nodepath)values("+ "'"+item.getLogin_username()+"',"+ "'"+item.getLogin_name()+"',"+ "'"+item.getIp()+"',"+ "'"+item.getLogintime()+"',"+ "'"+item.getLogin_area()+"',"+ ""+item.getLogin_area_id()+","+ "'"+item.getLogin_area_nodepath()+"')"; return executeUpdate(sql); }catch(Exception e){ System.out.println(e.toString()); return false; } finally{ DBclose(); } } /** * @author Administrator * @param item * @return keyId * @see */ public int addItemAndMaxId(Log_loginItem item){ try{ String sql="insert into "+T.LOG_LOGIN+"("+ "login_username,"+ "login_name,"+ "ip,"+ "logintime,"+ "login_area,"+ "login_area_id,"+ "login_area_nodepath)values("+ "'"+item.getLogin_username()+"',"+ "'"+item.getLogin_name()+"',"+ "'"+item.getIp()+"',"+ "'"+item.getLogintime()+"',"+ "'"+item.getLogin_area()+"',"+ ""+item.getLogin_area_id()+","+ "'"+item.getLogin_area_nodepath()+"')"; executeUpdate(sql); sql = "select max(id) as id from "+T.LOG_LOGIN; rs = executeQuery(sql); if (rs.next()) { keyId = rs.getInt("id"); return keyId; } else return 0; }catch(SQLException e){ System.out.println(e.toString()); return 0; } finally{ DBclose(); } } /** * @author Administrator * @param item:Log_loginItem * @return boolean * @see */ public boolean updateItem(Log_loginItem item){ try{ String sql="update "+T.LOG_LOGIN+" set "+ "login_username='"+item.getLogin_username()+"',"+ "login_name='"+item.getLogin_name()+"',"+ "ip='"+item.getIp()+"',"+ "logintime='"+item.getLogintime()+"',"+ "login_area='"+item.getLogin_area()+"',"+ "login_area_nodepath='"+item.getLogin_area_nodepath()+"' where id="+item.getId(); return executeUpdate(sql); }catch(Exception e){ System.out.println(e.toString()); return false; } finally{ DBclose(); } } /** * @author Administrator * @param item:Log_loginItem * @return boolean * @see */ public boolean updateItemNoFile(Log_loginItem item){ try{ String sql="update "+T.LOG_LOGIN+" set "+ "login_username='"+item.getLogin_username()+"',"+ "login_name='"+item.getLogin_name()+"',"+ "ip='"+item.getIp()+"',"+ "logintime='"+item.getLogintime()+"',"+ "login_area='"+item.getLogin_area()+"',"+ "login_area_nodepath='"+item.getLogin_area_nodepath()+"' where id="+item.getId(); return executeUpdate(sql); }catch(Exception e){ System.out.println(e.toString()); return false; } finally{ DBclose(); } } /** * @author Administrator * @param item:Log_loginItem * @return boolean * @see */ public boolean removeItem(Log_loginItem item){ try{ String sql="delete from "+T.LOG_LOGIN+" where id="+item.getId() ; return executeUpdate(sql); }catch(Exception e){ System.out.println(e.toString()); return false; } finally{ DBclose(); } } /** * @author Administrator * @param ids:array * @return boolean * @see */ public boolean removeItems(String[] ids) { try{ String sql="delete from "+T.LOG_LOGIN+" where id in ("; String filter=""; for(int i=0;i<ids.length-1;i++){ filter+=ids[i]+","; } filter+=ids[ids.length-1]+")"; sql+=filter; return executeUpdate(sql); }catch(Exception e){ System.out.println(e.toString()); return false; } finally{ DBclose(); } } /** * @author Administrator * @param sql * @return boolean * @see */ public boolean executeUpdate(String sql){ try{ access.getConnection(); return access.executeUpdate(sql); } catch(Exception e){ System.out.println(e.toString()); return false; } } /** * @author Administrator * @param sql * @return boolean * @see */ public ResultSet executeQuery(String sql){ try { access.getConnection(); rs=access.executeQuery(sql); return rs; } catch(Exception e){ System.out.println(e.toString()); return null; } } /** * @author Administrator * @param * @return * @see */ public void DBclose(){ try { access.DBclose(rs); } catch(Exception e) { System.out.println(e.toString()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -