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

📄 embedresultset.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			}		    boolean onRow = (currentRow!=null);			//if (onRow && !(currentRow instanceof org.apache.derby.impl.sql.execute.ValueRow))			//	System.out.println(currentRow.getClass());		    /*			    Connection.setAutoCommit says that a statement completes,			    and will autoCommit, when it fetches the last row or is closed.			    This means a close will get a "Cursor already closed" error.				This rule only applies when doing a next() - if it were applied				to scrolling actions (like FIRST or LAST) it would close				the cursor when doing any operation on a scrolling cursor.			    if autocommit, this will commit		     */		    if (!onRow && (position == NEXT)) {		     // In case of resultset for MetaData, we will only commit		     // if we are the only statement currently opened for this		     // connection; otherwise we don't want to affect other		     // resultSet's by committing the MetaData one.		     // There is no internal xact (xact isolation) for MetaData type		     // of resultSet; therefore committing (to release locks) would end		     // up committing all the other resultSet for this connection.		     //		     // We do synchronize on the connection, therefore Activation count		     // should be valid and protected.		     //			//LanguageConnectionContext lcc = getEmbedConnection().getLanguageConnection();		     if (forMetaData && (lcc.getActivationCount() > 1)) {		     	// we do not want to commit here as there seems to be other		     	// statements/resultSets currently opened for this connection.		     } else if (owningStmt != null)				 // allow the satement to commit if required.		     	owningStmt.resultSetClosing(this);		    }			rowData = onRow ? currentRow.getRowArray() : null;			return onRow;			} finally {			    restoreContextStack();			}		}	}    /**     * 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 thrown on failure.     */    public void close() throws SQLException	{		/* if this result is already closed, don't try to close again		 * we may have closed it earlier because of an error and trying		 * to close again will cause a different problem if the connection		 * has been closed as in XA error handling		 */		if (isClosed)			return;		closeCurrentStream();	// closing currentStream does not depend on the								// underlying connection.  Do this outside of								// the connection synchronization.		// Would like to throw an exception if already closed, but		// some code assumes you can close a ResultSet more than once.		// checkIfClosed("close");		// synchronize out here so the close and the autocommit are		// both in the same sync block.		synchronized (getConnectionSynchronization()) {			try {				setupContextStack(); // make sure there's context			} catch (SQLException se) {				// we may get an exception here if this is part of an XA transaction				// and the transaction has been committed				// just give up and return				return;			}			try	{				try	{				    theResults.finish(); // release the result set, don't just close it				} catch (Throwable t) {					throw handleException(t);				}			    // In case of resultset for MetaData, we will only commit		        // if we are the only statement currently opened for this		        // connection; otherwise we don't want to affect other		        // resultSet's by committing the MetaData one.		        // There is no internal xact (xact isolation) for MetaData type		        // of resultSet; therefore committing (to release locks) would end		        // up committing all the other resultSet for this connection.		        //		        // We do synchronize on the connection, therefore Activation count		        // should be valid and protected.		        //		        if (forMetaData) {					LanguageConnectionContext lcc = getEmbedConnection().getLanguageConnection();		        	if (lcc.getActivationCount() > 1) {		     		  // we do not want to commit here as there seems to be other					  // statements/resultSets currently opened for this connection.					} else if (owningStmt != null)						// allow the satement to commit if required.		     			owningStmt.resultSetClosing(this);						} else if (owningStmt != null) {						// allow the satement to commit if required.		     			owningStmt.resultSetClosing(this);		     	}			} finally {				isClosed = true;			    restoreContextStack();			}			// the idea is to release resources, so:			currentRow = null;			rowData = null;			rMetaData = null; // let it go, we can make a new one	    //since we are moving off of the current row(by closing the resultset), need to initialize state corresponding to updateRow implementation	    for (int i=0; i < columnGotUpdated.length; i++)				columnGotUpdated[i] = false;	    currentRowHasBeenUpdated = false;			// we hang on to theResults and messenger			// in case more calls come in on this resultSet		}	}    /**     * A column may have the value of SQL NULL; wasNull reports whether     * the last column read had this special value.     * Note that you must first call getXXX on a column to try to read     * its value and then call wasNull() to find if the value was     * the SQL NULL.     *     * <p> we take the least exception approach and simply return false     * if no column has been read yet.     *     * @return true if last column read was SQL NULL	 *	 * @exception SQLException		Thrown if this ResultSet is closed     */    public final boolean wasNull() throws SQLException {		checkIfClosed("wasNull");		return wasNull;	}    //======================================================================    // Methods for accessing results by column index    //======================================================================    /**     * Get the value of a column in the current row as a Java String.     *     * @param columnIndex the first column is 1, the second is 2, ...     * @return the column value; if the value is SQL NULL, the result is null	 * @exception SQLException thrown on failure.     */    public final String getString(int columnIndex) throws SQLException {			try {				DataValueDescriptor dvd = getColumn(columnIndex);				if (wasNull = dvd.isNull())					return null;				String value = dvd.getString();				// check for the max field size limit                 if (maxFieldSize > 0 && isMaxFieldSizeType(getColumnType(columnIndex)))                {                    if (value.length() > maxFieldSize )                    {                        value = value.substring(0, maxFieldSize);                    }                }     				return value;			} catch (Throwable t) {				throw noStateChangeException(t);			}	}    /**     * Get the value of a column in the current row as a Java boolean.     *     * @param columnIndex the first column is 1, the second is 2, ...     * @return the column value; if the value is SQL NULL, the result is false	 * @exception SQLException thrown on failure.     */    public final boolean getBoolean(int columnIndex) throws SQLException {		try {			DataValueDescriptor dvd = getColumn(columnIndex);			if (wasNull = dvd.isNull())				return false;			return dvd.getBoolean();		} catch (StandardException t) {			throw noStateChangeException(t);		}	}    /**     * Get the value of a column in the current row as a Java byte.     *     * @param columnIndex the first column is 1, the second is 2, ...     * @return the column value; if the value is SQL NULL, the result is 0	 * @exception SQLException thrown on failure.     */    public final byte getByte(int columnIndex) throws SQLException {		try {			DataValueDescriptor dvd = getColumn(columnIndex);			if (wasNull = dvd.isNull())				return 0;			return dvd.getByte();		} catch (StandardException t) {			throw noStateChangeException(t);		}	}    /**     * Get the value of a column in the current row as a Java short.     *     * @param columnIndex the first column is 1, the second is 2, ...     * @return the column value; if the value is SQL NULL, the result is 0	 * @exception SQLException thrown on failure.     */    public final short getShort(int columnIndex) throws SQLException {		try {			DataValueDescriptor dvd = getColumn(columnIndex);			if (wasNull = dvd.isNull())				return 0;			return dvd.getShort();		} catch (StandardException t) {			throw noStateChangeException(t);		}	}    /**     * Get the value of a column in the current row as a Java int.     *     * @param columnIndex the first column is 1, the second is 2, ...     * @return the column value; if the value is SQL NULL, the result is 0	 * @exception SQLException thrown on failure.     */    public final int getInt(int columnIndex) throws SQLException	{		try {			DataValueDescriptor dvd = getColumn(columnIndex);			if (wasNull = dvd.isNull())				return 0;			return dvd.getInt();		} catch (StandardException t) {			throw noStateChangeException(t);		}	}    /**     * Get the value of a column in the current row as a Java long.     *     * @param columnIndex the first column is 1, the second is 2, ...     * @return the column value; if the value is SQL NULL, the result is 0	 * @exception SQLException thrown on failure.     */    public final long getLong(int columnIndex) throws SQLException {		try {			DataValueDescriptor dvd = getColumn(columnIndex);			if (wasNull = dvd.isNull())				return 0;			return dvd.getLong();		} catch (StandardException t)	{			throw noStateChangeException(t);		}	}    /**     * Get the value of a column in the current row as a Java float.     *     * @param columnIndex the first column is 1, the second is 2, ...     * @return the column value; if the value is SQL NULL, the result is 0	 * @exception SQLException thrown on failure.     */    public final float getFloat(int columnIndex) throws SQLException {		try {			DataValueDescriptor dvd = getColumn(columnIndex);			if (wasNull = dvd.isNull())				return 0.0F;			return dvd.getFloat();		} catch (StandardException t)	{			throw noStateChangeException(t);		}	}    /**     * Get the value of a column in the current row as a Java double.     *     * @param columnIndex the first column is 1, the second is 2, ...     * @return the column value; if the value is SQL NULL, the result is 0	 * @exception SQLException thrown on failure.     */    public final double getDouble(int columnIndex) throws SQLException {		try {			DataValueDescriptor dvd = getColumn(columnIndex);			if (wasNull = dvd.isNull())				return 0.0;			return dvd.getDouble();		} catch (StandardException t)	{			throw noStateChangeException(t);		}	}    /**     * Get the value of a column in the current row as a Java byte array.     * The bytes represent the raw values returned by the driver.     *     * @param columnIndex the first column is 1, the second is 2, ...     * @return the column value; if the value is SQL NULL, the result is null	 * @exception SQLException thrown on failure.     */    public final byte[] getBytes(int columnIndex) throws SQLException	{		try {			DataValueDescriptor dvd = getColumn(columnIndex);			if (wasNull = dvd.isNull())				return null;			byte[] value = dvd.getBytes();            // check for the max field size limit             if (maxFieldSize > 0 && isMaxFieldSizeType(getColumnType(columnIndex)))            {                 if (value.length > maxFieldSize)                 {                     byte [] limited_value = new byte[maxFieldSize];                     System.arraycopy(value, 0, limited_value,                                                    0 , maxFieldSize);                     value = limited_value;                 }             }						return value;		} catch (StandardException t) {			throw noStateChangeException(t);		}	}    /**     * Get the value of a column in the current row as a java.sql.Date object.     *

⌨️ 快捷键说明

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