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

📄 resultset.java

📁 SearchPathServer
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
							if (year <= 69)
							{
								year = (year + 100);
							}
							return new java.sql.Timestamp(year, 0, 1, 0, 0, 0, 0);
						}
					default :
						throw new java.sql.SQLException(
							"Bad format for Timestamp '"
								+ S
								+ "' in column "
								+ columnIndex
								+ "("
								+ _fields[columnIndex
								- 1]
								+ ").",
							"S1009");
				}
			}
			
		}
		catch (Exception e)
		{
			throw new java.sql.SQLException(
				"Cannot convert value '"
					+ S
					+ "' from column "
					+ columnIndex
					+ "("
					+ S
					+ " ) to TIMESTAMP.",
				"S1009");
		}
	}

	/**
	 * A column value can be retrieved as a stream of ASCII characters
	 * and then read in chunks from the stream.  This method is
	 * particulary suitable for retrieving large LONGVARCHAR values.
	 * The JDBC driver will do any necessary conversion from the
	 * database format into ASCII.
	 *
	 * <p><B>Note:</B> All the data in the returned stream must be read
	 * prior to getting the value of any other column.  The next call
	 * to a get method implicitly closes the stream.  Also, a stream
	 * may return 0 for available() whether there is data available
	 * or not.
	 *
	 * @param columnIndex the first column is 1, the second is 2, ...
	 * @return a Java InputStream that delivers the database column
	 *    value as a stream of one byte ASCII characters.  If the
	 *    value is SQL NULL then the result is null
	 * @exception java.sql.SQLException if a database access error occurs
	 * @see getBinaryStream
	 */

	public InputStream getAsciiStream(int columnIndex) throws java.sql.SQLException
	{
		checkRowPos();

		return getBinaryStream(columnIndex);
	}

	/**
	 * A column value can also be retrieved as a stream of Unicode
	 * characters. We implement this as a binary stream.
	 *
	 * @param columnIndex the first column is 1, the second is 2...
	 * @return a Java InputStream that delivers the database column value
	 *    as a stream of two byte Unicode characters.  If the value is
	 *    SQL NULL, then the result is null
	 * @exception java.sql.SQLException if a database access error occurs
	 * @see getAsciiStream
	 * @see getBinaryStream
	 */

	public InputStream getUnicodeStream(int columnIndex)
		throws java.sql.SQLException
	{
		checkRowPos();

		return getBinaryStream(columnIndex);
	}

	/**
	 * A column value can also be retrieved as a binary strea.  This
	 * method is suitable for retrieving LONGVARBINARY values.
	 *
	 * @param columnIndex the first column is 1, the second is 2...
	 * @return a Java InputStream that delivers the database column value
	 * as a stream of bytes.  If the value is SQL NULL, then the result
	 * is null
	 * @exception java.sql.SQLException if a database access error occurs
	 * @see getAsciiStream
	 * @see getUnicodeStream
	 */

	public InputStream getBinaryStream(int columnIndex)
		throws java.sql.SQLException
	{
		checkRowPos();

		byte b[] = getBytes(columnIndex);

		if (b != null)
		{
			return new ByteArrayInputStream(b);
		}
		return null; // SQL NULL
	}

	/**
	 * The following routines simply convert the columnName into
	 * a columnIndex and then call the appropriate routine above.
	 *
	 * @param columnName is the SQL name of the column
	 * @return the column value
	 * @exception java.sql.SQLException if a database access error occurs
	 */

	public String getString(String ColumnName) throws java.sql.SQLException
	{
		return getString(findColumn(ColumnName));
	}

	public boolean getBoolean(String ColumnName) throws java.sql.SQLException
	{
		return getBoolean(findColumn(ColumnName));
	}

	public byte getByte(String ColumnName) throws java.sql.SQLException
	{
		return getByte(findColumn(ColumnName));
	}

	public short getShort(String ColumnName) throws java.sql.SQLException
	{
		return getShort(findColumn(ColumnName));
	}

	public int getInt(String ColumnName) throws java.sql.SQLException
	{
		return getInt(findColumn(ColumnName));
	}

	public long getLong(String ColumnName) throws java.sql.SQLException
	{
		return getLong(findColumn(ColumnName));
	}

	public float getFloat(String ColumnName) throws java.sql.SQLException
	{
		return getFloat(findColumn(ColumnName));
	}

	public double getDouble(String ColumnName) throws java.sql.SQLException
	{
		return getDouble(findColumn(ColumnName));
	}

	public BigDecimal getBigDecimal(String ColumnName, int scale)
		throws java.sql.SQLException
	{
		return getBigDecimal(findColumn(ColumnName), scale);
	}

	public byte[] getBytes(String ColumnName) throws java.sql.SQLException
	{
		return getBytes(findColumn(ColumnName));
	}

	public java.sql.Date getDate(String ColumnName) throws java.sql.SQLException
	{
		return getDate(findColumn(ColumnName));
	}

	public Time getTime(String ColumnName) throws java.sql.SQLException
	{
		return getTime(findColumn(ColumnName));
	}

	public Timestamp getTimestamp(String ColumnName) throws java.sql.SQLException
	{
		return getTimestamp(findColumn(ColumnName));
	}

	public InputStream getAsciiStream(String ColumnName)
		throws java.sql.SQLException
	{
		return getAsciiStream(findColumn(ColumnName));
	}

	public InputStream getUnicodeStream(String ColumnName)
		throws java.sql.SQLException
	{
		return getUnicodeStream(findColumn(ColumnName));
	}

	public InputStream getBinaryStream(String ColumnName)
		throws java.sql.SQLException
	{
		return getBinaryStream(findColumn(ColumnName));
	}

	/**
	 * The first warning reported by calls on this ResultSet is
	 * returned.  Subsequent ResultSet warnings will be chained
	 * to this java.sql.SQLWarning.
	 *
	 * <p>The warning chain is automatically cleared each time a new
	 * row is read.
	 *
	 * <p><B>Note:</B> This warning chain only covers warnings caused by
	 * ResultSet methods.  Any warnings caused by statement methods
	 * (such as reading OUT parameters) will be chained on the
	 * Statement object.
	 *
	 * @return the first java.sql.SQLWarning or null;
	 * @exception java.sql.SQLException if a database access error occurs.
	 */

	public java.sql.SQLWarning getWarnings() throws java.sql.SQLException
	{
		return _warnings;
	}

	/**
	 * After this call, getWarnings returns null until a new warning
	 * is reported for this ResultSet
	 *
	 * @exception java.sql.SQLException if a database access error occurs
	 */

	public void clearWarnings() throws java.sql.SQLException
	{
		_warnings = null;
	}

	/**
	 * Get the name of the SQL cursor used by this ResultSet
	 *
	 * <p>In SQL, a result table is retrieved though a cursor that is
	 * named.  The current row of a result can be updated or deleted
	 * using a positioned update/delete statement that references
	 * the cursor name.
	 *
	 * <p>JDBC supports this SQL feature by providing the name of the
	 * SQL cursor used by a ResultSet.  The current row of a ResulSet
	 * is also the current row of this SQL cursor.
	 *
	 * <p><B>Note:</B> If positioned update is not supported, a java.sql.SQLException
	 * is thrown.
	 *
	 * @return the ResultSet's SQL cursor name.
	 * @exception java.sql.SQLException if a database access error occurs
	 */

	public String getCursorName() throws java.sql.SQLException
	{
		throw new java.sql.SQLException("Positioned Update not supported.", "S1C00");
	}

	/**
	 * The numbers, types and properties of a ResultSet's columns are
	 * provided by the getMetaData method
	 *
	 * @return a description of the ResultSet's columns
	 * @exception java.sql.SQLException if a database access error occurs
	 */

	public abstract java.sql.ResultSetMetaData getMetaData()
		throws java.sql.SQLException;

	/**
	 * Get the value of a column in the current row as a Java object
	 *
	 * <p>This method will return the value of the given column as a
	 * Java object.  The type of the Java object will be the default
	 * Java Object type corresponding to the column's SQL type, following
	 * the mapping specified in the JDBC specification.
	 *
	 * <p>This method may also be used to read database specific abstract
	 * data types.
	 *
	 * @param columnIndex the first column is 1, the second is 2...
	 * @return a Object holding the column value
	 * @exception java.sql.SQLException if a database access error occurs
	 */

	public Object getObject(int columnIndex) throws java.sql.SQLException
	{
		checkRowPos();

		if (Driver.trace)
		{
			Object[] args = { new Integer(columnIndex)};
			Debug.methodCall(this, "getObject", args);
		}

		Field F;

		if (columnIndex < 1 || columnIndex > _fields.length)
		{
			throw new java.sql.SQLException(
				"Column index out of range (" + columnIndex + " > " + _fields.length + ").",
				"S1002");
		}
		F = _fields[columnIndex - 1];

		if (_thisRow[columnIndex - 1] == null)
		{
			_wasNullFlag = true;
			return null;
		}

		_wasNullFlag = false;

		switch (F.getSQLType())
		{
			case Types.BIT :
				return new Boolean(getBoolean(columnIndex));
			case Types.TINYINT :
				if (F.isUnsigned())
				{
					return new Integer(getInt(columnIndex));
				}
				else
				{
					return new Byte(getByte(columnIndex));
				}
			case Types.SMALLINT :
				if (F.isUnsigned())
				{
					return new Integer(getInt(columnIndex));
				}
				else
				{
					return new Short(getShort(columnIndex));
				}
			case Types.INTEGER :
				if (F.isUnsigned())
				{
					return new Long(getLong(columnIndex));
				}
				else
				{
					return new Integer(getInt(columnIndex));
				}
			case Types.BIGINT :
				return new Long(getLong(columnIndex));
			case Types.DECIMAL :
			case Types.NUMERIC :
				String S = getString(columnIndex);
				BigDecimal Val;

				if (S != null)
				{
					if (S.length() == 0)
					{
						Val = new BigDecimal(0);

						return Val;
					}
					try
					{
						Val = new BigDecimal(S);
					}
					catch (NumberFormatException E)
					{
						throw new java.sql.SQLException(
							"Bad format for BigDecimal '"
								+ S
								+ "' in column "
								+ columnIndex
								+ "("
								+ _fields[columnIndex
								- 1]
								+ ").",
							"S1009");
					}
					return Val;

				}
				else
				{
					return null;
				}
			case Types.REAL :
			case Types.FLOAT :
				return new Float(getFloat(columnIndex));
			case Types.DOUBLE :
				return new Double(getDouble(columnIndex));
			case Types.CHAR :
			case Types.VARCHAR :
			case Types.LONGVARCHAR :
				if (F.isBinary())
				{
					return getBytes(columnIndex);
				}
				else
				{
					return getString(columnIndex);
				}
			case Types.BINARY :
			case Types.VARBINARY :
			case Types.LONGVARBINARY :
				if (!F.isBlob())
				{
					return getString(columnIndex);
				}
				else if (!F.isBinary())
				{
					return getString(columnIndex);
				}
				else
				{

					byte[] Data = getBytes(columnIndex);

					Object Obj = Data;

					if (Data != null && Data.length >= 2)
					{
						if (Data[0] == -84 && Data[1] == -19)
						{
							// Serialized object?
							try
							{
								ByteArrayInputStream BIn = new ByteArrayInputStream(Data);
								ObjectInputStream ObjIn = new ObjectInputStream(BIn);

								Obj = ObjIn.readObject();
								ObjIn.close();
								BIn.close();
							}
							catch (ClassNotFoundException CnFe)
							{
								throw new SQLException(
									"Class not found: " + CnFe.toString() + " while reading serialized object");
							}
							catch (IOException Ex)
							{
								Obj = Data; // not serialized?
							}
						}

					}

					return Obj;
				}

			case Types.DATE :
				return getDate(columnIndex);
			case Types.TIME :
				return getTime(columnIndex);
			case Types.TIMESTAMP :
				return getTimestamp(columnIndex);
			default :
				return getString(columnIndex);
		}
	}

	/**
	 * Get the value of a column in the current row as a Java object
	 *
	 *<p> This method will return the value of the given column as a
	 * Java object.  The type of the Java object will be the default
	 * Java Object type corresponding to the column's SQL type, following
	 * the mapping specified in the JDBC specification.
	 *
	 * <p>This method may also be used to read database specific abstract
	 * data types.
	 *
	 * @param columnName is the SQL name of the column
	 * @return a Object holding the column value
	 * @exception java.sql.SQLException if a database access error occurs
	 */

	public Object getObject(String ColumnName) throws java.sql.SQLException
	{
		return getObject(findColumn(ColumnName));
	}

	/**
	 * Map a ResultSet column name to a ResultSet column index
	 *
	 * @param columnName the name of the column
	 * @return the column index
	 * @exception java.sql.SQLException if a database access error occurs
	 */

	public int findColumn(String ColumnName) throws java.sql.SQLException
	{
		Integer index;

		index = (Integer) _columnNameToIndex.get(ColumnName);

		if (index == null)
		{
			index = (Integer) _fullColumnNameToIndex.get(ColumnName);
		}

		if (index != null)
		{
			return index.intValue() + 1;
		}
		else
		{

			// Try this inefficient way, now

			String columnNameUC = ColumnName.toUpperCase();

			for (int i = 0; i < _fields.length; i++)
			{
				if (_fields[i].getName().toUpperCase().equals(columnNameUC))
				{
					return i + 1;
				}
				else if (_fields[i].getFullName().toUpperCase().equals(columnNameUC))
				{
					return i + 1;
				}
			}

			throw new java.sql.SQLException(
				"Column '" + ColumnName + "' not found.",
				"S0022");
		}
	}

	// ****************************************************************
	//
	//                       END OF PUBLIC INTERFACE
	//
	// ****************************************************************

	/**
	 * Create a new ResultSet - Note that we create ResultSets to
	 * represent the results of everything.
	 *
	 * @param fields an array of Field objects (basically, the
	 *    ResultSet MetaData)
	 * @param tuples Vector of the actual data

⌨️ 快捷键说明

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