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

📄 resultset.java

📁 SearchPathServer
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
		try
		{
			if (_thisRow[columnIndex - 1] == null)
			{
				_wasNullFlag = true;
			}
			else
			{
				_wasNullFlag = false;
			}
		}
		catch (NullPointerException E)
		{
			_wasNullFlag = true;
		}

		if (_wasNullFlag)
		{
			return 0;
		}

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

	/**
	 * Get the value of a column in the current row as a
	 * java.lang.BigDecimal object
	 *
	 * @param columnIndex  the first column is 1, the second is 2...
	 * @param scale the number of digits to the right of the decimal
	 * @return the column value; if the value is SQL NULL, null
	 * @exception java.sql.SQLException if a database access error occurs
	 */

	public BigDecimal getBigDecimal(int columnIndex, int scale)
		throws java.sql.SQLException
	{
		String S = getString(columnIndex);
		BigDecimal Val;

		if (S != null)
		{
			if (S.length() == 0)
			{
				Val = new BigDecimal(0);
				return Val.setScale(scale);
			}
			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");
			}
			try
			{
				return Val.setScale(scale);
			}
			catch (ArithmeticException E)
			{
				throw new java.sql.SQLException(
					"Bad format for BigDecimal '"
						+ S
						+ "' in column "
						+ columnIndex
						+ "("
						+ _fields[columnIndex
						- 1]
						+ ").",
					"S1009");
			}
		}
		return null; // SQL NULL
	}

	/**
	 * Get the value of a column in the current row as a Java byte array.
	 *
	 * <p><b>Be warned</b> If the blob is huge, then you may run out
	 * of memory.
	 *
	 * @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 java.sql.SQLException if a database access error occurs
	 */

	public byte[] getBytes(int columnIndex) throws java.sql.SQLException
	{
		checkRowPos();

		if (columnIndex < 1 || columnIndex > _fields.length)
			throw new java.sql.SQLException(
				"Column Index out of range ( " + columnIndex + " > " + _fields.length + ").",
				"S1002");

		try
		{
			if (_thisRow[columnIndex - 1] == null)
			{
				_wasNullFlag = true;
			}
			else
			{
				_wasNullFlag = false;
			}
		}
		catch (NullPointerException E)
		{
			_wasNullFlag = true;
		}

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

	/**
	 * Get the value of a column in the current row as a java.sql.Date
	 * object
	 *
	 * @param columnIndex the first column is 1, the second is 2...
	 * @return the column value; null if SQL NULL
	 * @exception java.sql.SQLException if a database access error occurs
	 */

	public java.sql.Date getDate(int columnIndex) throws java.sql.SQLException
	{
		Integer Y = null, M = null, D = null;
		String S = "";

		try
		{
			S = getString(columnIndex);
		
			if (S == null)
			{
				return null;
			}
			else if (S.equals("0000-00-00"))
			{
				_wasNullFlag = true;

				return null;
			}
			else if (
				_fields[columnIndex - 1].getMysqlType() == MysqlDefs.FIELD_TYPE_TIMESTAMP)
			{
				// Convert from TIMESTAMP
				switch (S.length())
				{
					case 14 :
					case 8 :
						{
							Y = new Integer(S.substring(0, 4));
							M = new Integer(S.substring(4, 6));
							D = new Integer(S.substring(6, 8));
							return new java.sql.Date(Y.intValue() - 1900, M.intValue() - 1, D.intValue());
						}
					case 12 :
					case 10 :
					case 6 :
						{
							Y = new Integer(S.substring(0, 2));

							if (Y.intValue() <= 69)
							{
								Y = new Integer(Y.intValue() + 100);
							}
							M = new Integer(S.substring(2, 4));
							D = new Integer(S.substring(4, 6));
							return new java.sql.Date(Y.intValue(), M.intValue() - 1, D.intValue());
						}
					case 4 :
						{
							Y = new Integer(S.substring(0, 4));

							if (Y.intValue() <= 69)
							{
								Y = new Integer(Y.intValue() + 100);
							}
							M = new Integer(S.substring(2, 4));
							return new java.sql.Date(Y.intValue(), M.intValue() - 1, 1);
						}
					case 2 :
						{
							Y = new Integer(S.substring(0, 2));

							if (Y.intValue() <= 69)
							{
								Y = new Integer(Y.intValue() + 100);
							}
							return new java.sql.Date(Y.intValue(), 0, 1);
						}
					default :
						throw new SQLException(
							"Bad format for Date '"
								+ S
								+ "' in column "
								+ columnIndex
								+ "("
								+ _fields[columnIndex
								- 1]
								+ ").",
							"S1009");
				} /* endswitch */
			}
			else if (_fields[columnIndex - 1].getMysqlType() == MysqlDefs.FIELD_TYPE_YEAR)
			{
				Y = new Integer(S.substring(0, 4));

				return new java.sql.Date(Y.intValue() - 1900, 0, 1);
			}
			else
			{
				if (S.length() < 10)
				{
					throw new SQLException(
						"Bad format for Date '"
							+ S
							+ "' in column "
							+ columnIndex
							+ "("
							+ _fields[columnIndex
							- 1]
							+ ").",
						"S1009");
				}

				Y = new Integer(S.substring(0, 4));
				M = new Integer(S.substring(5, 7));
				D = new Integer(S.substring(8, 10));
			}

			return new java.sql.Date(Y.intValue() - 1900, M.intValue() - 1, D.intValue());
		}
		catch (Exception e)
		{
			throw new java.sql.SQLException(
				"Cannot convert value '"
					+ S
					+ "' from column "
					+ columnIndex
					+ "("
					+ S
					+ " ) to DATE.",
				"S1009");
		}
	}

	/**
	 * Get the value of a column in the current row as a java.sql.Time
	 * object
	 *
	 * @param columnIndex the first column is 1, the second is 2...
	 * @return the column value; null if SQL NULL
	 * @exception java.sql.SQLException if a database access error occurs
	 */

	public Time getTime(int columnIndex) throws java.sql.SQLException
	{
		int hr = 0, min = 0, sec = 0;

		try
		{
			String S = getString(columnIndex);
			if (S == null)
			{
				return null;
			}
			else if (S.equals("0000-00-00"))
			{
				_wasNullFlag = true;

				return null;
			}

			Field F = _fields[columnIndex - 1];

			if (F.getMysqlType() == MysqlDefs.FIELD_TYPE_TIMESTAMP)
			{
				// It's a timestamp
				int length = S.length();
				switch (length)
				{
					case 14 :
					case 12 :
						{
							hr = Integer.parseInt(S.substring(length - 6, length - 4));
							min = Integer.parseInt(S.substring(length - 4, length - 2));
							sec = Integer.parseInt(S.substring(length - 2, length));
						}
						break;
					case 10 :
						{
							hr = Integer.parseInt(S.substring(6, 8));
							min = Integer.parseInt(S.substring(8, 10));
							sec = 0;
						}
						break;
					default :
						throw new SQLException(
							"Timestamp too small to convert to Time value in column "
								+ columnIndex
								+ "("
								+ _fields[columnIndex
								- 1]
								+ ").",
							"S1009");
				} /* endswitch */

				SQLWarning W =
					new SQLWarning(
						"Precision lost converting TIMESTAMP to Time with getTime() on column "
							+ columnIndex
							+ "("
							+ _fields[columnIndex
							- 1]
							+ ").");

				if (_warnings == null)
				{
					_warnings = W;
				}
				else
				{
					_warnings.setNextWarning(W);
				}
			}
			else if (F.getMysqlType() == MysqlDefs.FIELD_TYPE_DATETIME)
			{

				hr = Integer.parseInt(S.substring(11, 13));
				min = Integer.parseInt(S.substring(14, 16));
				sec = Integer.parseInt(S.substring(17, 19));

				SQLWarning W =
					new SQLWarning(
						"Precision lost converting DATETIME to Time with getTime() on column "
							+ columnIndex
							+ "("
							+ _fields[columnIndex
							- 1]
							+ ").");

				if (_warnings == null)
				{
					_warnings = W;
				}
				else
				{
					_warnings.setNextWarning(W);
				}
			}
			else
			{
				// convert a String to a Time

				if (S.length() != 5 && S.length() != 8)
				{
					throw new SQLException(
						"Bad format for Time '"
							+ S
							+ "' in column "
							+ columnIndex
							+ "("
							+ _fields[columnIndex
							- 1]
							+ ").",
						"S1009");
				}

				hr = Integer.parseInt(S.substring(0, 2));
				min = Integer.parseInt(S.substring(3, 5));
				sec = (S.length() == 5) ? 0 : Integer.parseInt(S.substring(6));
			}
			return new Time(hr, min, sec);
		}
		catch (Exception E)
		{
			throw new java.sql.SQLException(E.getClass().getName(), "S1009");
		}
	}

	/**
	 * Get the value of a column in the current row as a
	 * java.sql.Timestamp object
	 *
	 * @param columnIndex the first column is 1, the second is 2...
	 * @return the column value; null if SQL NULL
	 * @exception java.sql.SQLException if a database access error occurs
	 */

	public Timestamp getTimestamp(int columnIndex) throws java.sql.SQLException
	{
		String S = getString(columnIndex);

		try
		{
			if (S == null)
			{
				return null;
			}
			else if (S.equals("0000-00-00"))
			{
				_wasNullFlag = true;

				return null;
			}
			else if (_fields[columnIndex - 1].getMysqlType() == MysqlDefs.FIELD_TYPE_YEAR)
			{
				return new java.sql.Timestamp(Integer.parseInt(S.substring(0, 4)) - 1900, 0, 1, 0, 0, 0, 0);
			}
			else
			{
				// Convert from TIMESTAMP or DATE
			
				switch (S.length())
				{
					case 19 :
						{
							int year = Integer.parseInt(S.substring(0, 4));
							int month = Integer.parseInt(S.substring(5, 7));
							int day = Integer.parseInt(S.substring(8, 10));
							int hour = Integer.parseInt(S.substring(11, 13));
							int minutes = Integer.parseInt(S.substring(14, 16));
							int seconds = Integer.parseInt(S.substring(17, 19));
	
							return new java.sql.Timestamp(
								year - 1900,
								month - 1,
								day,
								hour,
								minutes,
								seconds,
								0);
						}
					case 14 :
						{
							int year = Integer.parseInt(S.substring(0, 4));
							int month = Integer.parseInt(S.substring(4, 6));
							int day = Integer.parseInt(S.substring(6, 8));
							int hour = Integer.parseInt(S.substring(8, 10));
							int minutes = Integer.parseInt(S.substring(10, 12));
							int seconds = Integer.parseInt(S.substring(12, 14));
							return new java.sql.Timestamp(
								year - 1900,
								month - 1,
								day,
								hour,
								minutes,
								seconds,
								0);
						}
					case 12 :
						{
							int year = Integer.parseInt(S.substring(0, 2));
	
							if (year <= 69)
							{
								year = (year + 100);
							}
							int month = Integer.parseInt(S.substring(2, 4));
							int day = Integer.parseInt(S.substring(4, 6));
							int hour = Integer.parseInt(S.substring(6, 8));
							int minutes = Integer.parseInt(S.substring(8, 10));
							int seconds = Integer.parseInt(S.substring(10, 12));
							return new java.sql.Timestamp(year, month - 1, day, hour, minutes, seconds, 0);
						}
					case 10 :
						{
							int year = Integer.parseInt(S.substring(0, 2));
							if (year <= 69)
							{
								year = (year + 100);
							}
							int month = Integer.parseInt(S.substring(2, 4));
							int day = Integer.parseInt(S.substring(4, 6));
							int hour = Integer.parseInt(S.substring(6, 8));
							int minutes = Integer.parseInt(S.substring(8, 10));
							return new java.sql.Timestamp(year, month - 1, day, hour, minutes, 0, 0);
						}
					case 8 :
						{
							int year = Integer.parseInt(S.substring(0, 4));
							int month = Integer.parseInt(S.substring(4, 6));
							int day = Integer.parseInt(S.substring(6, 8));
							return new java.sql.Timestamp(year - 1900, month - 1, day, 0, 0, 0, 0);
						}
					case 6 :
						{
							int year = Integer.parseInt(S.substring(0, 2));
							if (year <= 69)
							{
								year = (year + 100);
							}
							int month = Integer.parseInt(S.substring(2, 4));
							int day = Integer.parseInt(S.substring(4, 6));
							return new java.sql.Timestamp(year, month - 1, day, 0, 0, 0, 0);
						}
					case 4 :
						{
							int year = Integer.parseInt(S.substring(0, 2));
							if (year <= 69)
							{
								year = (year + 100);
							}
							int month = Integer.parseInt(S.substring(2, 4));
							return new java.sql.Timestamp(year, month - 1, 1, 0, 0, 0, 0);
						}
					case 2 :
						{
							int year = Integer.parseInt(S.substring(0, 2));

⌨️ 快捷键说明

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