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

📄 logdao.java

📁 这是一个JSP网站程序
💻 JAVA
字号:
package com.yibo.yiqu.db;

import com.yibo.yiqu.domain.super_user;
import com.yibo.yiqu.domain.super_user_info;
import java.util.*;
import java.sql.*;
/**
 * @author liuzhaofeng
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class LogDAO{
	
	Connection con;
//count the super_user login in the table supser_user
  public boolean Count(String name)
    {
        boolean flag = false;
        try
        {
            con = DataMYSQConnection.getConnectionbase();
        }
        catch(Exception exception)
        {
            System.out.println("运行代号: LogDAO 001");
        }
        String s = "update super_user set count=count+1 where name='"+name+"'";
        try
        {
            PreparedStatement preparedstatement = con.prepareStatement(s);
            preparedstatement.execute();
            flag = true;
        }
        catch(Exception exception1)
        {
        	System.out.println("运行代号:LogDAO 002");
        }
        finally
        {
            if(con != null)
                try
                {
                    con.close();
                }
                catch(Exception exception3) 
                {
                	System.out.println("运行代号: LogDAO 003");
                }
        }
        return flag;
    } 
    
    //insert login info
    public void insertInfo(String ip,String log_time,String log_info,int sort)
        throws Exception
    {
        try
        {
            con = DataMYSQConnection.getConnectionbase();
        }
        catch(Exception e)
        {
            throw e;
        }
        String relive = "insert into super_user_info (ip_address,log_time,log_info,sort) values (?,?,'"+log_info+"',?)";
        try
        {
            PreparedStatement pstmt = con.prepareStatement(relive);
            pstmt.setString(1, ip);
            pstmt.setString(2, log_time);
            pstmt.setInt(3,sort);
            pstmt.executeUpdate();
            con.close();
        }
        catch(SQLException e)
        {
            //throw e;
            System.out.println("运行代号:LogDAO 004 运行正常..."+e);
        }
        finally
        {
            try
            {
                if(con != null)
                    con.close();
            }
            catch(Exception e2) { }
        }
    }
    //get the user's id
	public int getId(String name)
			throws Exception
	{
		int val;
		val = 0;
		try
		{
			con = DataMYSQConnection.getConnectionbase();
		}		
		catch(Exception e1)
		{
			throw e1;
		}
		String check = "select * from super_user where name=?";
		try
		{
			PreparedStatement pstmt = con.prepareStatement(check);
			pstmt.setString(1,name);
			ResultSet rs= pstmt.executeQuery();
			if(rs.next())
			{
				val = rs.getInt("id");
			}
			con.close();
		}catch(SQLException e)
		{
			System.out.println("运行代号:LogDAO 005 运行正常...");
		}
	    finally
        {
            try
            {
                if(con != null)
                    con.close();
            }
            catch(Exception exception1) {}
        }
        return val;
	}
 //update the password of the users 
  public boolean passChange(super_user su)
    {
        boolean flag = false;
        Connection con = null;
        try
        {
            con = DataMYSQConnection.getConnectionbase();
        }
        catch(Exception exception)
        {
            System.out.println("运行代号: LogDAO 0000014");
        }
        String s = "update  super_user set password=? where id=?";
        try
        {
            PreparedStatement preparedstatement = con.prepareStatement(s);
            preparedstatement.setString(1, su.getPassword());
            preparedstatement.setInt(2, su.getId());
            preparedstatement.execute();
            flag = true;
        }
        catch(Exception exception1)
        {
        	System.out.println("运行代号: LogDAO 0015");
        }
        finally
        {
            if(con != null)
                try
                {
                    con.close();
                }
                catch(Exception exception3) 
                {
                	System.out.println("运行代号: LogDAO 0016");
                }
        }
        return flag;
    }
    //get the loginfo of users
  public ArrayList getLogInfo(int sort)
  {
  	ArrayList arraylist = new ArrayList();
  	try
  	{
  		con = DataMYSQConnection.getConnectionbase();
  	}catch(Exception e)
  	{
  		System.out.println("运行代号: LogDAO 0017");
  	}
  	String getlist = "select * from super_user_info where sort=?";
  	try
  	{
  		PreparedStatement pstmt = con.prepareStatement(getlist);
  		pstmt.setInt(1,sort);
  		super_user_info bean;
  		for(ResultSet rs = pstmt.executeQuery(); rs.next(); arraylist.add(bean))
  		{
  			bean = new super_user_info();
  			bean.setId(rs.getInt("id"));
  			bean.setIp_address(rs.getString("ip_address"));
  			bean.setLog_info(rs.getString("log_info"));
  			bean.setLog_time(rs.getString("log_time"));
  			bean.setSort(rs.getInt("sort"));
  		}
  	}catch(Exception e)
  	{
  		System.out.println("运行代号: LogDAO 0017");
  	}
  	finally
  	{
  		if(con!=null)
  		try
  		{
  			con.close();
  		}
  		catch(Exception e){}
  	}
  	return arraylist;
  }
  //得到管理员的登陆次数
	public int getLogCount(String name)
			throws Exception
	{
		int val;
		val = 0;
		try
		{
			con = DataMYSQConnection.getConnectionbase();
		}		
		catch(Exception e1)
		{
			throw e1;
		}
		String check = "select * from super_user where name=?";
		try
		{
			PreparedStatement pstmt = con.prepareStatement(check);
			pstmt.setString(1,name);
			ResultSet rs= pstmt.executeQuery();
			if(rs.next())
			{
				val = rs.getInt("Count");
			}
			con.close();
		}catch(SQLException e)
		{
			System.out.println("运行代号:LogDAO 005 运行正常...");
		}
	    finally
        {
            try
            {
                if(con != null)
                    con.close();
            }
            catch(Exception exception1) {}
        }
        return val;
	}
}

⌨️ 快捷键说明

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