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

📄 resultset.java

📁 SearchPathServer
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	 * @param status the status string returned from the back end
	 * @param updateCount the number of rows affected by the operation
	 * @param cursor the positioned update/delete cursor name
	 */

	public ResultSet(
		Field[] Fields,
		Vector Tuples,
		com.mysql.jdbc.Connection Conn)
	{
		this(Fields, Tuples);
		setConnection(Conn);
	}

	public ResultSet(Field[] Fields, Vector Tuples)
	{
		_currentRow = -1;
		this._fields = Fields;
		_rows = Tuples;
		_updateCount = (long) _rows.size();
		if (Driver.debug)
			System.out.println("Retrieved " + _updateCount + " rows");
		_reallyResult = true;

		// Check for no results

		if (_rows.size() > 0)
		{
			_thisRow = (byte[][]) _rows.elementAt(0);

			if (_updateCount == 1)
			{
				if (_thisRow == null)
				{
					_currentRow = -1;
					_rows.removeAllElements(); // empty result set
					_updateCount = -1;
				}
			}
		}
		else
		{
			_thisRow = null;
		}

		buildIndexMapping();

	}

	void setStatement(com.mysql.jdbc.Statement stmt)
	{
		_owningStatement = stmt;
	}

	/** 
	 * Builds a hash between column names and their indices for fast
	 * retrieval.
	 */

	protected void buildIndexMapping()
	{
		int numFields = _fields.length;

		_columnNameToIndex = new Hashtable();
		_fullColumnNameToIndex = new Hashtable();

		for (int i = 0; i < numFields; i++)
		{
			Integer index = new Integer(i);

			String columnName = _fields[i].getName();
			String fullColumnName = _fields[i].getFullName();

			if (columnName != null)
			{
				_columnNameToIndex.put(columnName, index);
				_columnNameToIndex.put(columnName.toUpperCase(), index);
				_columnNameToIndex.put(columnName.toLowerCase(), index);
			}

			if (fullColumnName != null)
			{
				_fullColumnNameToIndex.put(fullColumnName, index);
				_fullColumnNameToIndex.put(fullColumnName.toUpperCase(), index);
				_fullColumnNameToIndex.put(fullColumnName.toLowerCase(), index);
			}
		}
	}

	/**
	 * Create a result set for an executeUpdate statement.
	 *
	 * @param updateCount the number of rows affected by the update
	 */

	public ResultSet(long updateCount, long updateID)
	{
		this._updateCount = updateCount;
		this._updateID = updateID;
		_reallyResult = false;
		_fields = new Field[0];
	}

	public void setConnection(com.mysql.jdbc.Connection Conn)
	{
		this._connection = Conn;
	}

	boolean reallyResult()
	{
		return _reallyResult;
	}

	long getUpdateCount()
	{
		return _updateCount;
	}

	long getUpdateID()
	{
		return _updateID;
	}

	protected void checkRowPos() throws SQLException
	{

		if (_closed)
		{
			throw new SQLException("Operation not allowed after ResultSet closed");
		}

		if (_currentRow < 0)
		{
			throw new SQLException("Before start of result set");
		}

		if (_currentRow == _rows.size())
		{
			throw new SQLException("After end of result set");
		}
	}

	///////////////////////////////////////////
	//
	// These number conversion routines save
	// a ton of "new()s", especially for the heavily
	// used getInt() and getDouble() methods
	//
	///////////////////////////////////////////

	/**
	 * Converts a string representation of a number
	 * to a double. Need a faster way to do this.
	 */

	public static double getDouble(byte[] buf) throws SQLException
	{
		if (buf.length == 0)
		{
			return 0;
		}
		
		try 
		{
			return Double.parseDouble(new String(buf));
		} 
		catch (NumberFormatException e) 
		{
			throw new SQLException("Bad format for number '" + new String(buf) + "'");
		}

	}

	// 
	// Following adopted from Sun class libraries
	//

	/**
	 * All possible chars for representing a number as a String
	 */

	private final static char[] digits =
		{
			'0',
			'1',
			'2',
			'3',
			'4',
			'5',
			'6',
			'7',
			'8',
			'9',
			'a',
			'b',
			'c',
			'd',
			'e',
			'f',
			'g',
			'h',
			'i',
			'j',
			'k',
			'l',
			'm',
			'n',
			'o',
			'p',
			'q',
			'r',
			's',
			't',
			'u',
			'v',
			'w',
			'x',
			'y',
			'z' };

	/**
	 * Array of chars to lookup the char for the digit in the tenth's
	 * place for a two digit, base ten number.  The char can be got by
	 * using the number as the index.
	 */

	private final static char[] radixTenTenths =
		{
			'0',
			'0',
			'0',
			'0',
			'0',
			'0',
			'0',
			'0',
			'0',
			'0',
			'1',
			'1',
			'1',
			'1',
			'1',
			'1',
			'1',
			'1',
			'1',
			'1',
			'2',
			'2',
			'2',
			'2',
			'2',
			'2',
			'2',
			'2',
			'2',
			'2',
			'3',
			'3',
			'3',
			'3',
			'3',
			'3',
			'3',
			'3',
			'3',
			'3',
			'4',
			'4',
			'4',
			'4',
			'4',
			'4',
			'4',
			'4',
			'4',
			'4',
			'5',
			'5',
			'5',
			'5',
			'5',
			'5',
			'5',
			'5',
			'5',
			'5',
			'6',
			'6',
			'6',
			'6',
			'6',
			'6',
			'6',
			'6',
			'6',
			'6',
			'7',
			'7',
			'7',
			'7',
			'7',
			'7',
			'7',
			'7',
			'7',
			'7',
			'8',
			'8',
			'8',
			'8',
			'8',
			'8',
			'8',
			'8',
			'8',
			'8',
			'9',
			'9',
			'9',
			'9',
			'9',
			'9',
			'9',
			'9',
			'9',
			'9' };

	/**
	 * Array of chars to lookup the char for the digit in the unit's
	 * place for a two digit, base ten number.  The char can be got by
	 * using the number as the index.
	 */

	private final static char[] radixTenUnits =
		{
			'0',
			'1',
			'2',
			'3',
			'4',
			'5',
			'6',
			'7',
			'8',
			'9',
			'0',
			'1',
			'2',
			'3',
			'4',
			'5',
			'6',
			'7',
			'8',
			'9',
			'0',
			'1',
			'2',
			'3',
			'4',
			'5',
			'6',
			'7',
			'8',
			'9',
			'0',
			'1',
			'2',
			'3',
			'4',
			'5',
			'6',
			'7',
			'8',
			'9',
			'0',
			'1',
			'2',
			'3',
			'4',
			'5',
			'6',
			'7',
			'8',
			'9',
			'0',
			'1',
			'2',
			'3',
			'4',
			'5',
			'6',
			'7',
			'8',
			'9',
			'0',
			'1',
			'2',
			'3',
			'4',
			'5',
			'6',
			'7',
			'8',
			'9',
			'0',
			'1',
			'2',
			'3',
			'4',
			'5',
			'6',
			'7',
			'8',
			'9',
			'0',
			'1',
			'2',
			'3',
			'4',
			'5',
			'6',
			'7',
			'8',
			'9',
			'0',
			'1',
			'2',
			'3',
			'4',
			'5',
			'6',
			'7',
			'8',
			'9' };

	/**
	 * Converts a string representation of an long
	 * into an long
	 */

	public long getLong(byte[] buf) throws NumberFormatException
	{

		long result = 0;
		boolean negative = false;
		int i = 0, max = buf.length;
		long limit;
		long multmin;
		int digit;

		int radix = 10;

		if (max > 0)
		{
			if ((char) buf[0] == '-')
			{
				negative = true;
				limit = Long.MIN_VALUE;
				i++;
			}
			else
			{
				limit = -Long.MAX_VALUE;
			}

			multmin = limit / radix;

			if (i < max)
			{
				digit = Character.digit((char) buf[i++], radix);

				if (digit < 0)
				{
					throw new NumberFormatException(new String(buf));
				}
				else
				{
					result = -digit;
				}
			}

			while (i < max)
			{
				// Accumulating negatively avoids surprises near MAX_VALUE
				digit = Character.digit((char) buf[i++], radix);
				if (digit < 0)
				{
					throw new NumberFormatException(new String(buf));
				}
				if (result < multmin)
				{
					throw new NumberFormatException(new String(buf));
				}
				result *= radix;
				if (result < limit + digit)
				{
					throw new NumberFormatException(new String(buf));
				}
				result -= digit;
			}
		}
		else
		{
			throw new NumberFormatException(new String(buf));
		}
		if (negative)
		{
			if (i > 1)
			{
				return result;
			}
			else
			{ /* Only got "-" */
				throw new NumberFormatException(new String(buf));
			}
		}
		else
		{
			return -result;
		}
	}

	/**
	 * Sets the result set type for (JDBC2)
	 */

	protected void setResultSetType(int typeFlag)
	{
		_resultSetType = typeFlag;
	}

	/**
	 * Sets the concurrency (JDBC2)
	 */

	protected void setResultSetConcurrency(int concurrencyFlag)
	{
		_resultSetConcurrency = concurrencyFlag;
	}
}

⌨️ 快捷键说明

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