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

📄 counter.java

📁 动态网站管理发布系统
💻 JAVA
字号:
package com.ntsky.common;

import com.ntsky.database.SQLDBOperator;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Counter
{

    private SQLDBOperator sdbo;

    public Counter()
    {
        sdbo = null;
    }

    public boolean isIp(String ip)
    {
        boolean isIp = false;
        if(sdbo == null)
            sdbo = SQLDBOperator.getInstance("Connection");
        ResultSet rs = null;
        String strSql = "select * from newscommon where ip=?;";
        try
        {
            sdbo.prepareStatement(strSql);
            sdbo.setString(1, ip);
            rs = sdbo.executeQuery();
            try
            {
                rs.last();
                if(rs.getRow() > 0)
                    isIp = true;
                rs.close();
            }
            catch(NullPointerException nullE)
            {
                System.out.print("Counter isIp() " + nullE.getMessage());
                Debug.writeLog("Counter isIp(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
            }
        }
        catch(SQLException sqlE)
        {
            System.out.print("Counter isIp() " + sqlE.getMessage());
            Debug.writeLog("Counter isIp(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
        }
        finally
        {
            sdbo.Close();
        }
        return isIp;
    }

    public int counter()
    {
        int counter = 0;
        if(sdbo == null)
            sdbo = SQLDBOperator.getInstance("Connection");
        ResultSet rs = null;
        String strSql = "select * from newscommon;";
        try
        {
            rs = sdbo.executeQuery(strSql);
            try
            {
                rs.next();
                counter = rs.getInt("counter");
                rs.close();
            }
            catch(NullPointerException nullE)
            {
                System.out.print("Counter isIp() " + nullE.getMessage());
                Debug.writeLog("Counter isIp(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
            }
        }
        catch(SQLException sqlE)
        {
            System.out.print("Counter isIp() " + sqlE.getMessage());
            Debug.writeLog("Counter isIp(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
        }
        finally
        {
            sdbo.Close();
        }
        return counter;
    }

    public void upCounter(String ip)
    {
        if(sdbo == null)
            sdbo = SQLDBOperator.getInstance("Connection");
        String strSql = "update newscommon set counter=counter+1,ip=?;";
        try
        {
            sdbo.prepareStatement(strSql);
            sdbo.setString(1, ip);
            sdbo.executeUpdate();
        }
        catch(Exception e)
        {
            System.out.print("Counter upCounter() " + e.getMessage());
            Debug.writeLog("Counter upCounter(), Exception Occured ! Info :" + e.getLocalizedMessage());
        }
        finally
        {
            sdbo.Close();
        }
    }
}

⌨️ 快捷键说明

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