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

📄 checklogin.java

📁 jsp +javabean +sql 2000的在线聊天系统 ,实现私聊、群聊、管理员T人等功能
💻 JAVA
字号:
package net.chat;
import java.sql.*;
import java.util.*
import java.text.SimpleDateFormat;
public class CheckLogin{
/*
 检测用户登陆信息
 用户登陆的用户名
 用户登陆的密码
 */
 public Sting checklogin(Sting userName,Sting userPassword) throws SQLException,ClassNotFoundException
 {
 		BaseConn conn=null;
		try
		{
			conn=new BaseConn();
			//创建一个预先处理的SQL语句
			String sql="select *from userInfo where nickName=?";
			//创建一个预先处理的SQL对象
			PreparedStatement ps =conn.preparedStatement(sql);
			ps.setString(1,userName);
			//从用户数据库中查询该用户名是否在数据库中
			ResultSet rs=conn.executeQuery();
			if(rs.next())
			{
				if(rs.getString("userPassword").equals(userPassword)
				{
					SimpleDataFormat cal=new SimpleDataFormat("yyyy-MM-dd HH:mm:ss");
					String time=cal.format(new java.util.Data());
					//修改用户的最后登陆时间
					sql="update userinfo set lastLoginTime?where nickName=?";
					ps=conn.preparedStatement(sql);
					ps.setString(1,time)
					ps.setString(2,userName);
					conn.executeUpate();
					return "SUCCESS_LOGIN";
				}
				else
					return "WRONG_PASSWORD";
			}
			else
				   return "NONE_USER";
	      }catch(SQLException ex)
		  {
		  		ex.printStackTrace();
				throw ex;
		  }catch(ClassNotFoundException ex)
		  {
		  		ex.printStackTrace();
				throw ex;
		  }
		  finally
		  {
		  		conn.close();//关闭数据库连接,释放JDBC资源
		  }
 }
 /*
  如果是新用户,则将用户登陆用户名和密码保存到数据库中
 */
 public boolean saveToDataBase(String userName,String userPassword)
 throws SQLException,ClassNotFoundException
 {
 		BaseConn conn=null;
		try
		{	
			conn=new BaseConn();
			SimpleDateFormat cal=new SimoleDateFormat("yyyy-MM-dd HH:mm:ss");
			String time=cal.format(new java.util.Data());
			String sql="insert into userInfo(nickName,userPassword,lastLoginTime)values (?,?,?);
			PreparedStatemtent ps =conn.preparedStatement(Sql);
			ps.setString(1,userName);
			ps.setString(2,userPassword);
			ps.setString(3,time);
			conn.excuteUpdate();
			return true;
		}catch(SQLException ex)
		{
			ex.printStackTrace();
			throw ex;
		}finally
		{
			conn.close();//关闭数据库连接,释放JDBC资源
		}
	}
}
		  
		  
		  
		  
		  
		  
		  
		  
		  
		  
		  
		  
		  
		  

⌨️ 快捷键说明

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