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

📄 lists.java

📁 毕业设计源代码
💻 JAVA
字号:
package JXC.web;

import JXC.Com.DBConnect;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;

/**
 * Title:        物品列表
 * Description:
 * Copyright:    Copyright (c) 2003
 * Company:      torch
 *
 * @version 1.0
 * @author: wind
 */

public class Lists extends Pages {
    private String[] columnNames = {};
    private ResultSetMetaData metaData;
    int FRow = 0;
    int columnCount = 0;
    String StrSql = "";

    public Lists() throws Exception {
        super();
    }

    public String getColumnName(int column) {
        if (column >= columnCount)
            column = columnCount - 1;

        if (column < 0)
            column = 0;

        if (columnNames[column] != null) {
            return columnNames[column];
        } else
            return "";

    }

    public int getColumnIndex(String name) {
        int ok = 0;
        if (name != null) {
            for (int i = 0; i < columnCount; i++) {
                String temp = columnNames[i].toLowerCase();
                name = name.toLowerCase();
                if (name.equals(temp)) {
                    ok = i;
                    break;
                }

            }
        }
        return ok;
    }

    public void setRow(int i) {
        FRow = i;
    }

    public int getColumnCount() {
        return columnNames.length;
    }

    public Class getColumnClass(int column) {
        int type;
        try {
            type = metaData.getColumnType(column + 1);
        }
        catch (SQLException e) {
            return null;
        }

        switch (type) {
            case Types.CHAR:
            case Types.VARCHAR:
            case Types.LONGVARCHAR:
                return String.class;

            case Types.BIT:
                return Boolean.class;

            case Types.TINYINT:
            case Types.SMALLINT:
            case Types.INTEGER:
                return Integer.class;

            case Types.BIGINT:
                return Long.class;

            case Types.FLOAT:
            case Types.DOUBLE:
                return Double.class;

            case Types.DATE:
                return java.sql.Date.class;

            default:
                return Object.class;
        }
    }

    public String getString(int aColumn) {
        String[] row = (String[]) list.elementAt(FRow);
        return row[aColumn];
        //	Vector row = (Vector)list.elementAt(FRow);
        //	return row.elementAt(aColumn).toString();
    }

    public String getString(String aColumnName) {
        String[] row = (String[]) list.elementAt(FRow);
        return row[getColumnIndex(aColumnName)];
        //	Vector row = (Vector)list.elementAt(FRow);
        //	return row.elementAt(getColumnIndex(aColumnName)).toString();
    }

    public void setSql(String s) {
        String Str = "";
        Str = "select  * from " + s + " order by id desc";
        StrSql = Str;
    }

    public void setSql(String s, String where) {
        String Str = "";
        Str = "select * from " + s + " " + where + " order by id desc";
        StrSql = Str;
    }

    public void setStrSql(String Str) {
        StrSql = Str;
    }

    public String getSql() {
        return StrSql;
    }

    public boolean excute() throws Exception {
        int id = 0;
        try {
            DBConnect dbc = new DBConnect(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            String sql = getSql();
            System.out.println("===Lists.excute()==sql==" + sql);
            ResultSet rs = dbc.executeQuery(sql);

            metaData = rs.getMetaData();
            columnCount = metaData.getColumnCount();
            columnNames = new String[columnCount];
            // Get the column names and cache them.
            // Then we can close the connection.
            for (int column = 0; column < columnCount; column++) {
                columnNames[column] = metaData.getColumnLabel(column + 1);
            }
            rs.last();
            setShowPage(rs.getRow());
            rs.absolute(getRecode());
            System.out.println("====Lists.excute()==list==" + getPageSize());

            for (int i = 0; i < getPageSize(); i++) {
                String[] rsRow = new String[columnCount];
                for (int column = 0; column < columnCount; column++) {
                    rsRow[column] = rs.getString(column + 1);
                }
                list.addElement(rsRow);
                //	list.addElement(rs.getObject(i));
                if (!rs.next())
                    break;
            }
            System.out.println("====Lists.excute()==list==" + list);
            rs.close();
            dbc.close();
            return true;
        }
        catch (SQLException sqle) {
            return false;
        }
    }
}

⌨️ 快捷键说明

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