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

📄 tdsstatement.java

📁 Java写的TDS协议(JDBC/ODBC)实现
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                {
                    results = new TdsResultSet(tds, this, wChain, fetchSize);
                    break;
                }
                // SAfe: Only TDS_DONE should return row counts for Statements
                // TDS_DONEINPROC should return row counts for PreparedStatements
                else if( tds.peek()==Tds.TDS_DONE ||
                    (tds.getStatement() instanceof PreparedStatement &&
                    !(tds.getStatement() instanceof CallableStatement) &&
                    tds.peek()==Tds.TDS_DONEINPROC) )
                {
                    PacketEndTokenResult end =
                        (PacketEndTokenResult)tds.processSubPacket();
                    updateCount = end.getRowCount();

                    // SAfe Eat up all packets until the next result or the end
                    tds.goToNextResult(wChain);

                    if( allowTdsRelease )
                        releaseTds();
                    break;
                }
                // SAfe: TDS_DONEPROC and TDS_DONEINPROC should *NOT* return
                //       rowcounts otherwise
                else if( tds.isEndOfResults() )
                {
                    tds.processSubPacket();

                    // SAfe Eat up all packets until the next result or the end
                    tds.goToNextResult(wChain);

                    if( !tds.moreResults() )
                    {
                        if( allowTdsRelease )
                            releaseTds();
                        break; // No more results but no update count either
                    }
                }
                else if( tds.isMessagePacket() || tds.isErrorPacket() )
                    wChain.addOrReturn((PacketMsgResult)tds.processSubPacket());
                else if (tds.isRetStat())
                    handleRetStat((PacketRetStatResult)tds.processSubPacket());
                else if( tds.isParamResult() )
                    handleParamResult((PacketOutputParamResult)tds.processSubPacket());
                else if( tds.isEnvChange() )
                    // Process the environment change.
                    tds.processSubPacket();
                else if( tds.isProcId() )
                    tds.processSubPacket();
                else
                    throw new SQLException("Protocol confusion. Got a 0x"
                        + Integer.toHexString((tds.peek() & 0xff)) + " packet.");
            } // end while

            wChain.checkForExceptions();

            return results != null;
        }

        catch( Exception ex )
        {
            // SAfe we should not eat up all input. Even if an error was
            //      returned, this doesn't mean there isn't valid data after it.
//            try
//            {
//                tds.skipToEnd();
//            }
//            catch( Exception exc )
//            {}
            releaseTds();
            if( ex instanceof SQLException )
                throw (SQLException)ex;
            else
                throw new SQLException("Network error: " + ex.getMessage());
        }
    }

    //--------------------------JDBC 2.0-----------------------------

    /**
     * JDBC 2.0
     *
     * Gives the driver a hint as to the direction in which
     * the rows in a result set
     * will be processed. The hint applies only to result sets created
     * using this Statement object.  The default value is
     * ResultSet.FETCH_FORWARD.
     * <p>Note that this method sets the default fetch direction for
     * result sets generated by this <code>Statement</code> object.
     * Each result set has its own methods for getting and setting
     * its own fetch direction.
     * @param direction the initial direction for processing rows
     * @exception SQLException if a database access error occurs
     * or the given direction
     * is not one of ResultSet.FETCH_FORWARD, ResultSet.FETCH_REVERSE, or
     * ResultSet.FETCH_UNKNOWN
     */
    public void setFetchDirection(int direction) throws SQLException
    {
        if( direction!=ResultSet.FETCH_FORWARD && direction!=ResultSet.FETCH_REVERSE && direction!=ResultSet.FETCH_UNKNOWN )
            throw new SQLException("Invalid fetch direction.");
        fetchDir = direction;
    }

    /**
     * JDBC 2.0
     *
     * Retrieves the direction for fetching rows from
     * database tables that is the default for result sets
     * generated from this <code>Statement</code> object.
     * If this <code>Statement</code> object has not set
     * a fetch direction by calling the method <code>setFetchDirection</code>,
     * the return value is implementation-specific.
     *
     * @return the default fetch direction for result sets generated
     *          from this <code>Statement</code> object
     * @exception SQLException if a database access error occurs
     */
    public int getFetchDirection() throws SQLException
    {
        return fetchDir;
    }

    /**
     * JDBC 2.0
     *
     * Gives the JDBC driver a hint as to the number of rows that should
     * be fetched from the database when more rows are needed.  The number
     * of rows specified affects only result sets created using this
     * statement. If the value specified is zero, then the hint is ignored.
     * The default value is zero.
     *
     * @param rows the number of rows to fetch
     * @exception SQLException if a database access error occurs, or the
     * condition 0 <= rows <= this.getMaxRows() is not satisfied.
     */
    public void setFetchSize(int rows) throws SQLException
    {
        if( rows < 0 )
            throw new SQLException("Invalid fetch size.");
        fetchSize = rows;
    }

    /**
     * JDBC 2.0
     *
     * Retrieves the number of result set rows that is the default
     * fetch size for result sets
     * generated from this <code>Statement</code> object.
     * If this <code>Statement</code> object has not set
     * a fetch size by calling the method <code>setFetchSize</code>,
     * the return value is implementation-specific.
     * @return the default fetch size for result sets generated
     *          from this <code>Statement</code> object
     * @exception SQLException if a database access error occurs
     */
    public int getFetchSize() throws SQLException
    {
        return fetchSize;
    }

    /**
     * JDBC 2.0
     *
     * Retrieves the result set concurrency.
     * <p>
     * <b>Note:</b> No need for synchronization. Value never changes.
     */
    public int getResultSetConcurrency() throws SQLException
    {
        checkClosed();
        return concurrency;
    }

    /**
     * JDBC 2.0
     *
     * Determine the result set type.
     * <p>
     * <b>Note:</b> No need for synchronization. Value never changes.
     */
    public int getResultSetType()  throws SQLException
    {
        checkClosed();
        return type;
    }

    /**
     * JDBC 2.0
     *
     * Adds a SQL command to the current batch of commmands for the statement.
     * This method is optional.
     *
     * @param sql typically this is a static SQL INSERT or UPDATE statement
     * @exception SQLException if a database access error occurs, or the
     * driver does not support batch statements
     */
    public void addBatch( String sql ) throws SQLException
    {
        NotImplemented();
    }

    /**
     * JDBC 2.0
     *
     * Makes 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 void clearBatch() throws SQLException
    {
        NotImplemented();
    }

    /**
     * JDBC 2.0
     *
     * Submits a batch of commands to the database for execution.
     * This method is optional.
     *
     * @return an array of update counts containing one element for each
     * command in the batch.  The array is ordered according
     * to the order in which commands were inserted into the batch.
     * @exception SQLException if a database access error occurs or the
     * driver does not support batch statements
     */
    public int[] executeBatch() throws SQLException
    {
        NotImplemented();
        return null;
    }

    /**
     * JDBC 2.0
     *
     * Returns the <code>Connection</code> object
     * that produced this <code>Statement</code> object.
     * <p>
     * <b>Note:</b> No need for synchromization here. <code>connection</code>
     * doesn't change during execution (not even after <code>close()</code>.
     *
     * @return the connection that produced this statement
     * @exception SQLException if a database access error occurs
     */
    public java.sql.Connection getConnection() throws SQLException
    {
        checkClosed();
        return connection;
    }

    /**
     * Changes the auto commit and transaction isolation level of
     * <code>actTds</code>.
     * <p>
     * <b>Note:</b> Needs synchronization because it operates on
     * <code>actTds</code>.
     */
    protected synchronized void changeSettings(boolean autoCommit,
        int transactionIsolationLevel) throws SQLException
    {
        if( actTds != null )
        {
            String query = actTds.sqlStatementForSettings(autoCommit,
                transactionIsolationLevel);

            if( query != null )
            {
                executeImpl(actTds, query, warningChain);
                skipToEnd();
            }
        }
    }

    private void checkClosed() throws SQLException
    {
        if( isClosed )
            throw new SQLException("Statement already closed.");
    }

    public boolean execute(String str, int param) throws java.sql.SQLException
    {
        throw new SQLException("Not Implemented");
    }

    public boolean execute(String str, String[] str1) throws java.sql.SQLException
    {
        throw new SQLException("Not Implemented");
    }

    public boolean execute(String str, int[] values) throws java.sql.SQLException
    {
        throw new SQLException("Not Implemented");
    }

    public int executeUpdate(String str, String[] str1) throws java.sql.SQLException
    {
        throw new SQLException("Not Implemented");
    }

    public int executeUpdate(String str, int[] values) throws java.sql.SQLException
    {
        throw new SQLException("Not Implemented");
    }

    public int executeUpdate(String str, int param) throws java.sql.SQLException
    {
        throw new SQLException("Not Implemented");
    }

    public java.sql.ResultSet getGeneratedKeys() throws java.sql.SQLException
    {
        throw new SQLException("Not Implemented");
    }

    public int getResultSetHoldability() throws java.sql.SQLException
    {
        throw new SQLException("Not Implemented");
    }
}

⌨️ 快捷键说明

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