📄 clubonline.java
字号:
package com.gamvan.club.user;import com.gamvan.conn.*;//import com.gamvan.tools.*;import java.sql.*; import java.util.Calendar;public class ClubOnline { private String sessionID = new String(); private String userName = new String(); private String userip = new String(); private String userArea = new String(); private String loginTime = new String(); private String lastTime = new String(); private String message = new String(); private int outTime = 60; //设置超时退出 private int userHide = 0; private int onlines = 0; ConnClub bridge = new ConnClub(); //格式化当前时间 java.text.SimpleDateFormat isNow = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private String now = isNow.format(new java.util.Date()); public void conClose(){ try{ //this.con.close(); }catch(Exception e){ message = "con:" + e.toString(); } } public void onlineUpdate() throws Exception{ if(onlineSelect()){ updateInfo(); }else{ addInfo(); } } public void offline() throws Exception{ String sqlCommand = new String(); //Calendar c = Calendar.getInstance(); //int s = c.get(Calendar.SECOND); //s -= outTime; //c.set(Calendar.SECOND, s); //String outtime = isNow.format(c.getTime()); Connection con = bridge.getConnection(); try{ //sqlCommand = "delete from GVclubOnline where lastTime> '#"+ outtime +"#'"; sqlCommand = "delete from GVclubOnline where datediff(s,lastTime,getdate()) >"+ outTime +""; PreparedStatement pps = con.prepareStatement(sqlCommand); pps.executeUpdate(); pps.close(); message = sqlCommand; }catch(Exception e){ message = sqlCommand + "offline:" + e.toString(); con.close(); }finally{ con.close(); } } public void allOnlines() throws Exception{ String sqlCommand = new String(); Connection con = bridge.getConnection(); try{ sqlCommand = "select count(*) as ol from GVclubOnline"; PreparedStatement pps = con.prepareStatement(sqlCommand); ResultSet rs; rs = pps.executeQuery(); if(rs.next()){ onlines = rs.getInt("ol"); } rs.close(); pps.close(); }catch(Exception e){ message = "allOnlines:" + e.toString(); con.close(); }finally{ con.close(); } } private void addInfo() throws Exception{ String sqlCommand = new String(); Connection con = bridge.getConnection(); try{ sqlCommand = "Insert Into GVclubOnline(sessionID, userName, userip"; sqlCommand += ", userArea, loginTime, lastTime, userHide)"; sqlCommand += " Values(?,?,?,?,?,?,?)"; PreparedStatement pps = con.prepareStatement(sqlCommand); pps.setString(1,sessionID); pps.setString(2,userName); pps.setString(3,userip); pps.setString(4,userArea); pps.setString(5,now); pps.setString(6,now); pps.setInt(7,userHide); pps.executeUpdate(); pps.close(); }catch(Exception e){ con.close(); message = "addInfo" + e.toString(); }finally{ con.close(); } } private void updateInfo() throws Exception{ String sqlCommand = new String(); Connection con = bridge.getConnection(); try{ sqlCommand = "Update GVclubOnline set userArea=?,lastTime=? where sessionID=?"; PreparedStatement pps = con.prepareStatement(sqlCommand); pps.setString(1,userArea); pps.setString(2,now); pps.setString(3,sessionID); pps.executeUpdate(); pps.close(); }catch(Exception e){ con.close(); message = "updateInfo" + e.toString(); }finally{ con.close(); } message = sqlCommand; } public boolean onlineSelect() throws Exception{ boolean bea = false; String sqlCommand = new String(); Connection con = bridge.getConnection(); try{ ResultSet rs; sqlCommand = "Select * From GVclubOnline where sessionID=?"; PreparedStatement pps = con.prepareStatement(sqlCommand); pps.setString(1, sessionID); rs = pps.executeQuery(); if(rs.next()){ sessionID = rs.getString(1); //userName = rs.getString(2); userip = rs.getString(3); //userArea = rs.getString(4); loginTime = rs.getString(5); lastTime = rs.getString(6); userHide = rs.getInt(7); bea = true; } rs.close(); pps.close(); }catch(Exception e){ con.close(); bea = false; message = "onlineSelect" + e.toString(); }finally{ con.close(); } return bea; //message=sqlCommand; } public String getMessage(){ return this.message; } public int getOnlines(){ return this.onlines; } public void setSessionID(String sessionID){ this.sessionID = sessionID; } public String getSessionID(){ return this.sessionID; } public void setOutTime(int outTime){ this.outTime = outTime; } public void setUserName(String userName){ if(userName==null){ this.userName = "今晚过客"; }else{ this.userName = userName; } } public String getUserName(){ return this.userName; } public void setUserip(String userip){ this.userip = userip; } public void setUserArea(String userArea){ this.userArea = userArea; } public String getUserArea(){ return this.userArea; } public void setLoginTime(String LoginTime){ this.loginTime = loginTime; } public String setLoginTime(){ return this.loginTime; } public void setLastTime(String lastTime){ this.lastTime = lastTime; } public String getLastTime(){ return this.lastTime; } public void setUserHide(String userHide){ this.userHide = Integer.parseInt(userHide); } public int getUserHide(){ return this.userHide; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -