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

📄 statement.java

📁 基于b/s的网上书店
💻 JAVA
📖 第 1 页 / 共 4 页
字号:

        return updateCount;
    }

    /**
     * Sets the maxFieldSize
     *
     * @param max the new max column size limit; zero means unlimited
     *
     * @exception SQLException if size exceeds buffer size
     * @throws SQLException DOCUMENT ME!
     */
    public void setMaxFieldSize(int max) throws SQLException {
        if (Driver.TRACE) {
            Object[] args = { new Integer(max) };
            Debug.methodCall(this, "setMaxFieldSize", args);
        }

        if (max < 0) {
            throw new SQLException("Illegal value for setMaxFieldSize()",
                SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
        }

        int maxBuf = (connection != null) ? connection.getMaxAllowedPacket()
                                          : MysqlIO.getMaxBuf();

        if (max > maxBuf) {
            throw new java.sql.SQLException(
                "Can not set max field size > max allowed packet: " + maxBuf,
                SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
        } else {
            maxFieldSize = max;
        }
    }

    /**
     * The maxFieldSize limit (in bytes) is the maximum amount of data returned
     * for any column value; it only applies to BINARY, VARBINARY,
     * LONGVARBINARY, CHAR, VARCHAR and LONGVARCHAR columns.  If the limit is
     * exceeded, the excess data is silently discarded.
     *
     * @return the current max column size limit; zero means unlimited
     *
     * @exception java.sql.SQLException if a database access error occurs
     */
    public int getMaxFieldSize() throws java.sql.SQLException {
        if (Driver.TRACE) {
            Object[] args = new Object[0];
            Debug.methodCall(this, "getMaxFieldSize", args);
        }

        return maxFieldSize;
    }

    /**
     * Set the maximum number of rows
     *
     * @param max the new max rows limit; zero means unlimited
     *
     * @exception java.sql.SQLException if a database access error occurs
     *
     * @see getMaxRows
     */
    public void setMaxRows(int max) throws java.sql.SQLException {
        if (Driver.TRACE) {
            Object[] args = { new Integer(max) };
            Debug.methodCall(this, "setMaxRows", args);
        }

        if ((max > MysqlDefs.MAX_ROWS) || (max < 0)) {
            throw new java.sql.SQLException("setMaxRows() out of range. " + max
                + " > " + MysqlDefs.MAX_ROWS + ".", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
        }

        if (max == 0) {
            max = -1;
        }

        this.maxRows = max;
        this.maxRowsChanged = true;

        if (maxRows == -1) {
            connection.unsetMaxRows(this);
            this.maxRowsChanged = false;
        } else {
            // Most people don't use setMaxRows()
            // so don't penalize them
            // with the extra query it takes
            // to do it efficiently unless we need
            // to.
            connection.maxRowsChanged(this);
        }
    }

    /**
     * The maxRows limit is set to limit the number of rows that any ResultSet
     * can contain.  If the limit is exceeded, the excess rows are silently
     * dropped.
     *
     * @return the current maximum row limit; zero means unlimited
     *
     * @exception java.sql.SQLException if a database access error occurs
     */
    public int getMaxRows() throws java.sql.SQLException {
        if (Driver.TRACE) {
            Object[] args = new Object[0];
            Debug.methodCall(this, "getMaxRows", args);
        }

        if (maxRows <= 0) {
            return 0;
        } else {
            return maxRows;
        }
    }

    /**
     * getMoreResults moves to a Statement's next result.  If it returns true,
     * this result is a ResulSet.
     *
     * @return true if the next ResultSet is valid
     *
     * @exception java.sql.SQLException if a database access error occurs
     */
    public boolean getMoreResults() throws java.sql.SQLException {
        if (Driver.TRACE) {
            Object[] args = new Object[0];
            Debug.methodCall(this, "getMoreResults", args);
        }

        return getMoreResults(CLOSE_CURRENT_RESULT);
    }

    /**
     * @see Statement#getMoreResults(int)
     */
    public synchronized boolean getMoreResults(int current)
        throws SQLException {
        switch (current) {
        case Statement.CLOSE_CURRENT_RESULT:

            if (results != null) {
                results.close();
            }

            break;

        case Statement.CLOSE_ALL_RESULTS:

            if (results != null) {
                results.close();
            }

            closeAllOpenResults();

            break;

        case Statement.KEEP_CURRENT_RESULT:
            openResults.add(results);

            break;

        default:
            throw new SQLException("Illegal flag for getMoreResults(int)",
                SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
        }

        results = nextResults;

        nextResults = null;

        return ((results != null) && results.reallyResult()) ? true : false;
    }

    /**
     * Sets the queryTimeout limit
     *
     * @param seconds - the new query timeout limit in seconds
     *
     * @exception SQLException if a database access error occurs
     */
    public void setQueryTimeout(int seconds) throws SQLException {
        if (Driver.TRACE) {
            Object[] args = { new Integer(seconds) };
            Debug.methodCall(this, "setQueryTimeout", args);
        }

        if (seconds < 0) {
            throw new SQLException("Illegal value for setQueryTimeout()",
                SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
        }

        timeout = seconds;
    }

    /**
     * The queryTimeout limit is the number of seconds the driver will wait for
     * a Statement to execute.  If the limit is exceeded, a
     * java.sql.SQLException is thrown.
     *
     * @return the current query timeout limit in seconds; 0 = unlimited
     *
     * @exception java.sql.SQLException if a database access error occurs
     */
    public int getQueryTimeout() throws java.sql.SQLException {
        if (Driver.TRACE) {
            Object[] args = new Object[0];
            Debug.methodCall(this, "getQueryTimeout", args);
        }

        return timeout;
    }

    /**
     * getResultSet returns the current result as a ResultSet.  It should only
     * be called once per result.
     *
     * @return the current result set; null if there are no more
     *
     * @exception java.sql.SQLException if a database access error occurs
     *            (why?)
     */
    public synchronized java.sql.ResultSet getResultSet()
        throws java.sql.SQLException {
        if (Driver.TRACE) {
            Object[] args = new Object[0];
            Debug.methodCall(this, "getResultSet", args);
        }

        return ((results != null) && results.reallyResult())
        ? (java.sql.ResultSet) results : null;
    }

    /**
     * JDBC 2.0 Determine the result set concurrency.
     *
     * @return CONCUR_UPDATABLE or CONCUR_READONLY
     *
     * @throws SQLException if an error occurs
     */
    public int getResultSetConcurrency() throws SQLException {
        return resultSetConcurrency;
    }

    /**
     * @see Statement#getResultSetHoldability()
     */
    public int getResultSetHoldability() throws SQLException {
        return ResultSet.HOLD_CURSORS_OVER_COMMIT;
    }

    /**
     * JDBC 2.0 Determine the result set type.
     *
     * @return the ResultSet type (SCROLL_SENSITIVE or SCROLL_INSENSITIVE)
     *
     * @throws SQLException if an error occurs.
     */
    public int getResultSetType() throws SQLException {
        return resultSetType;
    }

    /**
     * getUpdateCount returns the current result as an update count, if the
     * result is a ResultSet or there are no more results, -1 is returned.  It
     * should only be called once per result.
     *
     * @return the current result as an update count.
     *
     * @exception java.sql.SQLException if a database access error occurs
     */
    public synchronized int getUpdateCount() throws java.sql.SQLException {
        if (Driver.TRACE) {
            Object[] args = new Object[0];
            Debug.methodCall(this, "getUpdateCount", args);
        }

        if (results == null) {
            return -1;
        }

        if (results.reallyResult()) {
            return -1;
        }

        int truncatedUpdateCount = 0;

        if (results.getUpdateCount() > Integer.MAX_VALUE) {
            truncatedUpdateCount = Integer.MAX_VALUE;
        } else {
            truncatedUpdateCount = (int) results.getUpdateCount();
        }

        return truncatedUpdateCount;
    }

    /**
     * The first warning reported by calls on this Statement is returned.  A
     * Statement's execute methods clear its java.sql.SQLWarning chain.
     * Subsequent Statement warnings will be chained to this
     * java.sql.SQLWarning.
     * 
     * <p>
     * The Warning chain is automatically cleared each time a statement is
     * (re)executed.
     * </p>
     * 
     * <p>
     * <B>Note:</B>  If you are processing a ResultSet then any warnings
     * associated with ResultSet reads will be chained on the ResultSet
     * object.
     * </p>
     *
     * @return the first java.sql.SQLWarning on null
     *
     * @exception java.sql.SQLException if a database access error occurs
     */
    public synchronized java.sql.SQLWarning getWarnings()
        throws java.sql.SQLException {
        if (Driver.TRACE) {
            Object[] args = new Object[0];
            Debug.methodCall(this, "getWarnings", args);
        }

        return warningChain;
    }

    /**
     * DOCUMENT ME!
     *
     * @param sql DOCUMENT ME!
     *
     * @throws SQLException DOCUMENT ME!
     */
    public synchronized void addBatch(String sql) throws SQLException {
        if (batchedArgs == null) {
            batchedArgs = new ArrayList();
        }

        if (sql != null) {
            batchedArgs.add(sql);
        }
    }

    /**
     * Cancel can be used by one thread to cancel a statement that is being
     * executed by another thread.  However this driver is synchronous, so
     * this really has no meaning - we define it as a no-op (i.e. you can't
     * cancel, but there is no error if you try.)
     *
     * @exception java.sql.SQLException only because thats the spec.
     */
    public void cancel() throws java.sql.SQLException {
        if (Driver.TRACE) {
            Object[] args = new Object[0];
            Debug.methodCall(this, "cancel", args);
        }

        // No-op
    }

    /**
     * JDBC 2.0 Make the set of commands in the current batch empty. This
     * method is optional.
     *
     * @exception SQLException if a database-access error occurs, or the driver
     *            does not support batch statements
     */
    public synchronized void clearBatch() throws SQLException {
        if (batchedArgs != null) {
            batchedArgs.clear();
        }
    }

    /**
     * After this call, getWarnings returns null until a new warning is
     * reported for this Statement.
     *

⌨️ 快捷键说明

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