📄 clubonline.java
字号:
package com.gamvan.club.user;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.gamvan.conn.ConnClub;
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;
private int onUserID = 0;
ConnClub bridge = new ConnClub();
ClubMyFriends cmf = new ClubMyFriends();
//格式化当前时间
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();
Connection con = bridge.getConnection();
try{
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, onUserID)";
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.setInt(8,onUserID);
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 userName=?, userArea=?,lastTime=?, onUserID=? where sessionID=?";
PreparedStatement pps = con.prepareStatement(sqlCommand);
pps.setString(1,userName);
pps.setString(2,userArea);
pps.setString(3,now);
pps.setInt(4,onUserID);
pps.setString(5,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);
// onUserID = rs.getInt(9);
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 getLoginTime(){
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 void setOnUserID(int onUserID){
this.onUserID = onUserID;
}
public int getUserHide(){
return this.userHide;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -