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

📄 tdsresultset.java

📁 Java写的TDS协议(JDBC/ODBC)实现
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        checkClosed();
        return row == 1;
    }

    /**
     *  JDBC 2.0 <p>
     *
     *  Indicates whether the cursor is on the last row of the result set. Note:
     *  Calling the method <code>isLast</code> may be expensive because the JDBC
     *  driver might need to fetch ahead one row in order to determine whether
     *  the current row is the last row in the result set.
     *
     *@return                   true if the cursor is on the last row, false
     *      otherwise.
     *@exception  SQLException  if a database access error occurs
     */
    public boolean isLast() throws SQLException
    {
        /** @todo Implement isLast */
        throw new SQLException("Cannot determine position on a FORWARD_ONLY RecordSet.");
    }

    public int getRow() throws SQLException
    {
        checkClosed();
        return row;
    }

    public int getFetchDirection() throws SQLException
    {
        return ResultSet.FETCH_FORWARD;
    }

    public int getFetchSize() throws SQLException
    {
        checkClosed();
        return fetchSize;
    }

    public int getType() throws SQLException
    {
        return ResultSet.TYPE_FORWARD_ONLY;
    }

    public int getConcurrency() throws SQLException
    {
        return ResultSet.CONCUR_READ_ONLY;
    }

    public java.sql.Statement getStatement() throws SQLException
    {
        checkClosed();
        return stmt;
    }

    public void clearWarnings() throws SQLException
    {
        warningChain.clearWarnings();
    }

    /**
     *  In some cases, it is desirable to immediately release a ResultSet's
     *  database and JDBC resources instead of waiting for this to happen when
     *  it is automatically closed; the close method provides this immediate
     *  release. <P>
     *
     *  <B>Note:</B> A ResultSet is automatically closed by the Statement that
     *  generated it when that Statement is closed, re-executed, or is used to
     *  retrieve the next result from a sequence of multiple results. A
     *  ResultSet is also automatically closed when it is garbage collected.
     *
     *@exception  SQLException  if a database-access error occurs.
     */
    public synchronized void close() throws SQLException
    {
        close(true);
    }

    public synchronized void close(boolean allowTdsRelease) throws SQLException
    {
        Exception exception = null;

        if( isClosed )
            return;
        isClosed = true;

        if( !hitEndOfData )
        {
            try
            {
                tds.discardResultSetOld(context);
                hitEndOfData = true;
                if( allowTdsRelease )
                    stmt.releaseTds();
            }
            catch( TdsException e )
            {
                exception = e;
            }
            catch( java.io.IOException e )
            {
                exception = e;
            }
        }

        rowCache = null;
        metaData = null;
        context = null;
        stmt = null;
        tds = null;

        if( exception != null )
            throw new SQLException(exception.toString());
    }

    /**
     *  A ResultSet is initially positioned before its first row; the first call
     *  to next makes the first row the current row; the second call makes the
     *  second row the current row, etc. <P>
     *
     *  If an input stream from the previous row is open, it is implicitly
     *  closed. The ResultSet's warning chain is cleared when a new row is read.
     *
     *@return                   true if the new current row is valid; false if
     *      there are no more rows
     *@exception  SQLException  if a database-access error occurs.
     */
    public synchronized boolean next() throws SQLException
    {
        checkClosed();

        if( haveMoreResults() )
        {
            rowIndex++;
            row++;
            return true;
        }

        return false;
    }

    /** @todo fetchNextRow should not be public! Possible synchronization problem! */
    private PacketRowResult fetchNextRow() throws SQLException
    {
        checkClosed();

        PacketRowResult row = null;

        try
        {
            clearWarnings();

            // Keep eating garbage and warnings until we reach the next result
            while( !tds.isResultSet() &&
                   !tds.isEndOfResults() &&
                   !tds.isResultRow())
            {
                // RMK 2000-06-08: don't choke on RET_STAT package.
                if( tds.isProcId() || tds.isRetStat() )
                    tds.processSubPacket();
                else if( tds.isParamResult() )
                {
                    PacketResult tmp1 = tds.processSubPacket();

                    if( stmt!=null && stmt instanceof CallableStatement_base )
                        ((CallableStatement_base)stmt).addOutputParam(
                            ((PacketOutputParamResult)tmp1).getValue());
                }
                /*
                else if (tds.isTextUpdate()) {
                    PacketResult tmp1 =
                            (PacketResult) tds.processSubPacket();
                }
                 */
                else if( tds.isMessagePacket() || tds.isErrorPacket() )
                    warningChain.addOrReturn(
                        (PacketMsgResult)tds.processSubPacket());
                else
                    throw new SQLException("Protocol confusion. "
                        + "Got a 0x"
                        + Integer.toHexString((tds.peek() & 0xff))
                        + " packet");
            }

            // SAfe Only releases the tds if no more packets are outstanding.
            stmt.releaseTds();
            warningChain.checkForExceptions();

            if( tds.isResultRow() )
                row = (PacketRowResult)tds.processSubPacket(context);
            else if( tds.isEndOfResults() )
            {
                if( ((PacketEndTokenResult)tds.processSubPacket(context)).wasCanceled() )
                    warningChain.addException(
                        new SQLException("Query was canceled or timed out."));

                tds.goToNextResult(warningChain);

                row = null;
                hitEndOfData = true;
                stmt.releaseTds();
            }
            else if( !tds.isResultSet() )
                throw new SQLException("Protocol confusion. "
                    + "Got a 0x"
                    + Integer.toHexString((tds.peek() & 0xff))
                    + " packet");
        }
        catch( java.io.IOException e )
        {
            stmt.releaseTds();
            throw new SQLException(e.getMessage());
        }
        catch( TdsException e )
        {
            stmt.releaseTds();
            throw new SQLException(e.getMessage());
        }

        warningChain.checkForExceptions();

        return row;
    }


    public void beforeFirst() throws SQLException
    {
        throw new SQLException("The result set type is TYPE_FORWARD_ONLY");
    }

    /**
     *  JDBC 2.0 <p>
     *
     *  Moves the cursor to the end of the result set, just after the last row.
     *  Has no effect if the result set contains no rows.
     *
     *@exception  SQLException  if a database access error occurs or the result
     *      set type is TYPE_FORWARD_ONLY
     */
    public void afterLast() throws SQLException
    {
        throw new SQLException("The result set type is TYPE_FORWARD_ONLY");
    }

    /**
     *  JDBC 2.0 <p>
     *
     *  Moves the cursor to the first row in the result set.
     *
     *@return                   true if the cursor is on a valid row; false if
     *      there are no rows in the result set
     *@exception  SQLException  if a database access error occurs or the result
     *      set type is TYPE_FORWARD_ONLY
     */
    public boolean first() throws SQLException
    {
        throw new SQLException("The result set type is TYPE_FORWARD_ONLY");
    }

    /**
     *  JDBC 2.0 <p>
     *
     *  Moves the cursor to the last row in the result set.
     *
     *@return                   true if the cursor is on a valid row; false if
     *      there are no rows in the result set
     *@exception  SQLException  if a database access error occurs or the result
     *      set type is TYPE_FORWARD_ONLY.
     */
    public boolean last() throws SQLException
    {
        throw new SQLException("The result set type is TYPE_FORWARD_ONLY");
    }

    /**
     *  JDBC 2.0 <p>
     *
     *  Moves the cursor to the given row number in the result set. <p>
     *
     *  If the row number is positive, the cursor moves to the given row number
     *  with respect to the beginning of the result set. The first row is row 1,
     *  the second is row 2, and so on. <p>
     *
     *  If the given row number is negative, the cursor moves to an absolute row
     *  position with respect to the end of the result set. For example, calling
     *  <code>absolute(-1)</code> positions the cursor on the last row, <code>
     *  absolute(-2)</code> indicates the next-to-last row, and so on. <p>
     *
     *  An attempt to position the cursor beyond the first/last row in the
     *  result set leaves the cursor before/after the first/last row,
     *  respectively. <p>
     *
     *  Note: Calling <code>absolute(1)</code> is the same as calling <code>
     *  first()</code> . Calling <code>absolute(-1)</code> is the same as
     *  calling <code>last()</code> .
     *
     *@param  row
     *@return                   true if the cursor is on the result set; false
     *      otherwise
     *@exception  SQLException  if a database access error occurs or row is 0,
     *      or result set type is TYPE_FORWARD_ONLY.
     */
    public boolean absolute(int row) throws SQLException
    {
        throw new SQLException("The result set type is TYPE_FORWARD_ONLY");
    }

    /**
     *  JDBC 2.0 <p>
     *
     *  Moves the cursor a relative number of rows, either positive or negative.
     *  Attempting to move beyond the first/last row in the result set positions
     *  the cursor before/after the the first/last row. Calling <code>
     *  relative(0)</code> is valid, but does not change the cursor position.
     *  <p>
     *
     *  Note: Calling <code>relative(1)</code> is different from calling <code>

⌨️ 快捷键说明

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