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

📄 connary.java

📁 云网论坛CWBBS 源码,内容丰富,学习,参考,教学的好资料,具体见内说明,
💻 JAVA
字号:
package cn.js.fan.db;

import java.sql.*;
import java.util.*;
import java.io.*;
import java.lang.reflect.*;

public class ConnAry implements Serializable {
    Conn conn;
    String sql = null;
    int rowcount = 0;
    int colcount = 0;
// int limitcount = 0;
    Vector result = null;
    public String _WATCH = "";

    public ConnAry(String connname) {
        conn = new Conn(connname);
    }

    protected void finalize() throws Throwable {
        super.finalize();
        if (conn != null) conn.close();
        if (result != null) result.removeAllElements();
    }

    public void close() { // throws Throwable
        try {
            finalize();
        } catch (java.lang.Throwable e) {
            System.out.println("conn.close error:" + e.getMessage());
        }
    }

    public String get(int row, int col) {
        if (result == null || row >= result.size())return null;
        String r[] = (String[]) result.elementAt(row);
        if (col >= java.lang.reflect.Array.getLength(r))return null;
        return r[col];
    }

    public int getColumncount() {
        return colcount;
    }

    public Vector getResult() {
        return result;
    }

    public String[][] getResultAry() {
        if (rowcount == 0 || colcount == 0)
            return null;
        String[][] ary = new String[rowcount][colcount];
        for (int r = 0; r < rowcount; r++)
            for (int c = 0; c < colcount; c++) {
                ary[r][c] = get(r, c);
            }
        return ary;
    }

    public String[] getRow(int row) {
        if (result == null || row >= result.size())return null;
        return (String[]) result.elementAt(row);
        /*String ret[] = new String[colcount];
                 Vector r = (Vector)result.elementAt(row);
                 for (int i=0; i< colcount; i++)
                 ret[i] = (String)r.elementAt(i);
                 return ret;*/
    }

    public int getRowcount() {
        return rowcount;
    }

    public void handleException(Exception e) {
        _WATCH = e.getMessage();
        System.out.println(_WATCH);
    }

    public void init() {
        rowcount = 0;
        colcount = 0;
        // limitcount = 0;
        result = null;
    }

    public void clear() throws Throwable {
        finalize();
    }

    public int query(String sql) {
        if (result != null) result.removeAllElements();
        rowcount = 0;
        colcount = 0;
        result = new Vector();
        int ret = 0;
        try {
            ResultSet rs = conn.executeQuery(sql);
            if (rs == null) {
                //ret = conn.getAffectedRows();
                ret = 0;
            } else {
                ResultSetMetaData rm = rs.getMetaData();
                colcount = rm.getColumnCount();
                while (rs.next()) {
                    String row[] = new String[colcount];
                    for (int i = 0; i < colcount; i++)
                        row[i] = rs.getString(i + 1);
                    result.addElement(row);
                    rowcount++;
                }
                rs.close(); // to release the resource.
                ret = result.size();
            }
        } catch (Exception e) {
            handleException(e);
            return -1;
        }
        return ret;
    }

    public ResultSet executeQuery(String sql) throws SQLException {
        return conn.executeQuery(sql);
    }

    public int executeUpdate(String sql) throws SQLException {
        return conn.executeUpdate(sql);
    }

    public void beginTrans() throws SQLException {
        conn.beginTrans();
    }

    public void commit() throws SQLException {
        conn.commit();
    }

    public void rollback() {
        conn.rollback();
    }

    public boolean getAutoCommit() throws SQLException {
        return conn.getAutoCommit();
    }

    public int getTransactionIsolation() throws SQLException {
        return conn.getTransactionIsolation();
    }

}

⌨️ 快捷键说明

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