⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 user.java

📁 一个用java写的一种聊天工具
💻 JAVA
字号:
package business;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Comparator;

import DataLayer.SqlHelper;
public class User implements Comparator {
	public int userNum;
	public String userName;
	public String password;
	public int isOnLine;
	public String ip;
	public String userInformation;
	public int userLogo;
	public String sex;
	public String email;
	private static SqlHelper sh;
	public User()
	{
		
	}
	public User(int num,String name,String password,int online,String ip,String info,int logo,String sex,String email)
	{
		userNum = num;
		userName= name;
		this.password = password;
		this.isOnLine = online;
		this.ip = ip;
		this.userInformation = info ;
		this.userLogo = logo;
		this.sex = sex ;
		this.email = email;
	}
	
	public void updateUser()
	{
		  sh = new SqlHelper();
		  sh.setStatement(sh.getConnection());
		  sh.getUpdate("update tbl_Users set userName='"+userName+"',sex='"+sex+"',userInformation='"+userInformation+"',email='"+email+"',userLogo="+userLogo+" where userNum='"+userNum+"'");
	}
	public static User getUser(String que)
	{
		  sh = new SqlHelper();
		  sh.setStatement(sh.getConnection());
		  ResultSet rs = sh.getQuery(que);
		  User temp = null;
		  try {
			if(rs.next())
			{
				temp = new User(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getInt(4),rs.getString(5),rs.getString(6),rs.getInt(7),rs.getString(8),rs.getString(9));
			}
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		return temp;
	}
	public int compare(Object arg0, Object arg1) {
		// TODO 自动生成方法存根
		User u1 = (User)arg0;
		User u2 = (User)arg1;
		return u2.isOnLine - u1.isOnLine;
	}
	public boolean equals(Object obj)
	{
		User u = (User)obj;
		return this.isOnLine == u.isOnLine;
	}
	public static void setOnLine(int online,int user)
	{
		sh = new SqlHelper();
		sh.setStatement(sh.getConnection());
		sh.getUpdate("update tbl_Users set isOnLine ="+online + " where userNum="+user);
	}
	public static void setIP(String ip,int user)
	{
		sh = new SqlHelper();
		sh.setStatement(sh.getConnection());
		sh.getUpdate("update tbl_Users set IP ='"+ ip + "' where userNum="+user);
	}
	public static String getName(int userNum)
	{
		sh = new SqlHelper();
		sh.setStatement(sh.getConnection());
		ResultSet rs = sh.getQuery("select userName from tbl_Users where userNum="+userNum);
		String userName = null;
		try {
			if(rs.next())
			{
				userName = rs.getString(1);
			}
		} catch (SQLException e) {
		}
		return userName;
	}
	public static int getIsOnLine(int userNum)
	{
		sh = new SqlHelper();
		sh.setStatement(sh.getConnection());
		ResultSet rs = sh.getQuery("select isOnLine from tbl_Users where userNum="+userNum);
		int online = -1;
		try {
			if(rs.next())
			{
				online = rs.getInt(1);
			}
		} catch (SQLException e) {
		}
		return online;
	}
	public static String getInfo(int userNum)
	{
		sh = new SqlHelper();
		sh.setStatement(sh.getConnection());
		ResultSet rs = sh.getQuery("select userInformation from tbl_Users where userNum="+userNum);
		String userInformation = null;
		try {
			if(rs.next())
			{
				userInformation = rs.getString(1);
			}
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		return userInformation;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -