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

📄 dbloginrecorditerator.java

📁 一套完整的工商12315的源程序jsp部分在12315里,后台JAVA部分在gs12315src里,没有打包数据库.
💻 JAVA
字号:
/*
 * DbLoginRecordIterator.java
 *
 * Created on 2001年8月9日, 下午4:58
 */

package com.gs.db.dbimp;
import com.gs.db.*;

import java.util.Iterator;
import java.util.ListIterator;
import java.util.ArrayList;
import java.sql.*;

/**
 *
 * @author  administrator
 * @version
 */
public class DbLoginRecordIterator  implements Iterator, ListIterator {

    /** Creates new DbLoginRecordIterator */
    /** DATABASE QUERIES **/
    private static final String ALL_LR =
        "SELECT * from gsLogins where lastpulse+30000 > ?";

    private int currentIndex = -1;

    ArrayList records=new ArrayList();

    private IofficeFactory factory;

    protected DbLoginRecordIterator(IofficeFactory factory) {
        this.factory = factory;
        //We don't know how many results will be returned, so store them
        //in an ArrayList.
        Connection con = null;
        PreparedStatement pstmt = null;
        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(ALL_LR);
            pstmt.setLong( 1,(new java.util.Date()).getTime());
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                int userid = rs.getInt("userid");
                String ipAddr = rs.getString("ipaddr");
                long loginTime = rs.getLong("logintime");
                String doingWhat = rs.getString( "doingwhat");
                records.add(new DbLoginRecord(factory,userid,loginTime,doingWhat, ipAddr));
            }
        }
        catch( SQLException sqle ) {
            System.err.println("Error in DbLoginRecordIterator:constructor()-" + sqle);
        }
        finally {
            try {  pstmt.close(); }
            catch (Exception e) { e.printStackTrace(); }
            try {  con.close();   }
            catch (Exception e) { e.printStackTrace(); }
        }
    }

    /**
     * Returns true if there are more users left to iteratate through forwards.
     */
    public boolean hasNext() {
        return (currentIndex+1 < records.size());
    }


    /**
     * Returns the next User.
     *
     * @return the next User.
     * @throws NoSuchElementException if there are no more elements to return.
     */
    public Object next() throws java.util.NoSuchElementException {
        DbLoginRecord rec=null;
        currentIndex++;
        if (currentIndex >= records.size()) {
            throw new java.util.NoSuchElementException();
        }
       return  rec =(DbLoginRecord) records.get(currentIndex);
    }

   /**
     * For security reasons, the remove operation is not supported. Use
     * ProfileManager instead.
     *
     * @see ProfileManager
     */
    public void remove() {
        throw new UnsupportedOperationException();
    }

    /**
     * Returns true if there are more users left to iteratore through backwards.
     */
    public boolean hasPrevious() {
        return (currentIndex > 0);
    }

    /**
     * For security reasons, the add operation is not supported. Use
     * ProfileManager instead.
     *
     * @see ProfileManager
     */
    public void add(Object o) throws UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }

    /**
     * For security reasons, the set operation is not supported. Use
     * ProfileManager instead.
     *
     * @see ProfileManager
     */
    public void set(Object o) throws UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }

    /**
     * Returns the index number that would be returned with a call to next().
     */
    public int nextIndex() {
        return currentIndex+1;
    }

    /**
     * Returns the previous user.
     */
    public Object previous() throws java.util.NoSuchElementException {
        DbLoginRecord rec=null;
        currentIndex--;
        if (currentIndex < 0) {
            currentIndex++;
            throw new java.util.NoSuchElementException();
        }
       return  rec =(DbLoginRecord) records.get(currentIndex);
    }

    /**
     * Returns the index number that would be returned with a call to previous().
     */
    public int previousIndex() {
        return currentIndex-1;
    }

    public int getSize()
    {
        return records.size();
    }

}

⌨️ 快捷键说明

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