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

📄 tinysqlresultset.java

📁 TinySQL是一个轻量级的纯java数据库引擎
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
   * @exception SQLException in case of error
   * @param column the column being retrieved
   * @return the column as a double
   *
   */
  public double getDouble(int column)
    throws SQLException
  {

    // get the column as a string
    //
    String str = getString(column);

    // it it's null, return zero
    //
    if( str == null ) return 0;

    // attempt the conversion
    //
    try
    {
      return Double.valueOf( str.trim( )).doubleValue( );
    }
    catch( NumberFormatException e )
    {
      throw new SQLException( "tinySQL invalid double Number: " + e.getMessage( ));
    }
  }  

  /**
   *
   * Return a column as a BigDecimal object
   * @see java.sql.ResultSet#getBigDecimal
   * @exception SQLException in case of a problem
   * @param column the column being retrieved
   * @param scale the number of digits to the right of the decimal
   * @return the column as a BigDecimal
   * @deprecated
   */
  public BigDecimal getBigDecimal(int column, int scale)
       throws SQLException
  {

    // get the column as a string
    //
    String str = getString(column);

    // return null as zero, otherwise use the string
    //
    if( str == null )
      return new BigDecimal(new BigInteger("0"), scale);
    else
      return new BigDecimal( new BigInteger( str.trim( )), scale );
  }

  /**
   *
   * Get the value of a column in the current row as a Java byte array.
   * @see java.sql.ResultSet#getBytes
   * @exception SQLException thrown in case of trouble
   * @param column the column being retrieved
   * @return a byte array that is the value of the column
   *
   */
  public byte[] getBytes(int column) throws SQLException {

    // get the column as a string
    //
    String str = getString(column);

    if( str == null ) return null;
    try {
      return str.getBytes(str);
    }
    catch( java.io.UnsupportedEncodingException e ) {
      throw new java.sql.SQLException("Bad bytes!: " + e.getMessage());
    }

  }

  /**
   *
   * Get the value of a column in the current row as a java.sql.Date object.
   * @see java.sqlResultSet#getDate
   * @exception SQLException thrown in case of error
   * @param column the column being retrieved
   * @return the java.sql.Date object for the column
   *
   */
  public java.sql.Date getDate(int column)
       throws SQLException 
  {

    // get the column as a string in the format YYYY-MM-DD
    //
    String str;
    str = getString(column);

    // return null if the string is null
    //
    if( str == null ) return null;

    // try to use the string to instantiate a java.util.Date object,
    // then use that object to instantiate a java.sql.Date object.
    //
    try {
      SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
      java.util.Date d = fmt.parse(str, new ParsePosition(0));

      return new java.sql.Date(d.getTime());

    } catch( Exception e ) {
      throw new SQLException("Date format error: " + e.getMessage());
    }

  }

  /**
   *
   * Get the value of a column in the current row as a java.sql.Time object.
   *
   * @see java.sql.ResultSet#getTime
   * @exception SQLException thrown in the event of troubles
   * @param column the column being retrieved
   * @return the column as a java.sql.Time object
   *
   */
  public java.sql.Time getTime(int column)
       throws SQLException {

    // get the column as a string
    //
    String str = getString(column);

    // if the string is null, return null
    //
    if( str == null ) return null;

    // try to use the string to instantiate a java.util.Date object,
    // then use that object to instantiate a java.sql.Time object.
    //
    try {

      SimpleDateFormat fmt = new SimpleDateFormat("EEE MMM dd hh:mm:ss z yyyy");
      java.util.Date d = fmt.parse(str, new ParsePosition(0));

      return new java.sql.Time(d.getTime());

    } catch( Exception e ) {
      throw new SQLException("Data format error: " + e.getMessage());
    }
  }

  /**
   * Get the value of a column in the current row as a java.sql.Timestamp
   * @see java.sql.ResultSet#getTimestamp
   * @exception SQLException thrown in the event of troubles
   * @param column the column being retrieved
   * @return the column as a java.sql.Timestamp object
   */
  public java.sql.Timestamp getTimestamp(int column)
       throws SQLException {

    // get the column as a string
    //
    String str = getString(column);

    // if the string is null, return null
    //
    if( str == null ) return null;

    // try to use the string to instantiate a java.util.Date object,
    // then use that object to instantiate a java.sql.Timestamp object.
    //
    try {

      SimpleDateFormat fmt = new SimpleDateFormat("EEE MMM dd hh:mm:ss z yyyy");
      java.util.Date d = fmt.parse(str, new ParsePosition(0));

      return new java.sql.Timestamp(d.getTime());

    } catch( Exception e ) {
      throw new SQLException("Data format error: " + e.getMessage());
    }

  }

  /**
   *
   * This is not currently supported.
   *
   */
  public java.io.InputStream getAsciiStream(int column)
       throws SQLException {
    return null;
  }

  /**
   *
   * This is not currently supported.
   * @deprecated
   *
   */
  public java.io.InputStream getUnicodeStream(int column)
       throws SQLException {
    return null;
  }

  /**
   *
   * This is not currently supported.
   *
   */
  public java.io.InputStream getBinaryStream(int column)
       throws SQLException {
    return null;
  }


  /**
   *
   * Get the name of the cursor corresponding to this result set.
   * This has to meaning to tinySQL
   * @see java.sql.ResultSet#getCursorName
   * @return ""
   *
   */
  public String getCursorName() throws SQLException {
    return "";
  }

  /**
   *
   * Returns a ResultSetMetaData object for this result set
   * @see java.sql.ResultSet#getMetaData
   * @exception SQLException thrown on error getting meta-data
   * @return ResultSetMetaData object containing result set info
   *
   */
  public ResultSetMetaData getMetaData()
       throws SQLException {

    // if we didn't instantiate a meta data object, then
    // do so. Since it's a field of this object, and
    // not private to this method, it will stay around
    // between calls to this method.
    //
    if( meta == null ) {
      meta = new tinySQLResultSetMetaData(result);
    }

    // return the ResultSetMetaData object
    //
    return meta;
  }

  /**
   *
   * Retrieves data as objects
   * @see java.sql.ResultSet#getObject
   * @exception SQLException in the event of an error
   * @param column the column desired
   * @param type the SQL data type of the field
   * @scale precision for BigDecimals
   * @return the column specified as an Object
   *
   */
  public Object getObject(int column, int type, int scale)
       throws SQLException {

    switch(type) {
    case Types.BIT:
      return new Boolean(getBoolean(column));

    case Types.TINYINT:
      return new Character((char)getInt(column));

    case Types.SMALLINT:
      return new Integer(getShort(column));

    case Types.INTEGER:
      return new Integer(getInt(column));

    case Types.BIGINT:
      return new Long(getLong(column));

    case Types.FLOAT:
      return new Float(getFloat(column));

    case Types.REAL:
      return new Float(getFloat(column));

    case Types.DOUBLE:
      return new Double(getDouble(column));

    case Types.NUMERIC:
      return getBigDecimal(column, scale);

    case Types.DECIMAL:
      return getBigDecimal(column, scale);

    case Types.CHAR:
      return getString(column);

    case Types.VARCHAR:
      return getString(column);

    case Types.LONGVARCHAR:
      return getString(column);

    case Types.DATE:
      return getDate(column);

    case Types.TIME:
      return getTime(column);

    case Types.TIMESTAMP:
      return getTimestamp(column);

    case Types.BINARY:
      return getBytes(column);

    case Types.VARBINARY:
      return getBytes(column);

    case Types.LONGVARBINARY:
      return getBytes(column);

    default:
      return null;
    }
  }

  /**
   *
   * Same as above, except with a default scale to 0.
   *
   */
  public Object getObject(int column, int type)
       throws SQLException {
    return getObject(column, type, 0);
  }

  /**
   *
   * Same as above, except using the column's default SQL type.
   *
   */
  public Object getObject(int column) throws SQLException {
    ResultSetMetaData meta = getMetaData();
    int type = meta.getColumnType(column);

    return getObject(column, type);
  }

  /**
   *
   * Return the String value of a column given its name, rather than
   * its index.
   * @see java.sql.ResultSet#getString
   * @param name the name of the column desired
   * @return the value of the column as a String
   *
   */
  public String getString(String name) throws SQLException {

    return getString(findColumn(name));

  }

  /**
   *
   * Returns the column as a byte based on column name
   *
   */
  public byte getByte(String columnName) throws SQLException {

    return getByte(findColumn(columnName));

  }

  /**
   *
   * Get the value of a boolean column in the current row
   * @param columnName is the SQL name of the column
   * @return the column value; if isNull the value is false
   *
   */
  public boolean getBoolean(String columnName) throws SQLException {

    return getBoolean(findColumn(columnName));

  }

  /**
   *
   * Get the value of a short by column name
   * @param columnName is the SQL name of the column
   * @return the column value; if isNull the value is 0
   *
   */
  public short getShort(String columnName) throws SQLException {

    return getShort(findColumn(columnName));

  }

  /**
   *
   * Get the integer value of a column by name
   * @param columnName is the SQL name of the column
   * @return the column value; if isNull the value is 0
   *
   */
  public int getInt(String columnName) throws SQLException {

    return getInt(findColumn(columnName));

  }

⌨️ 快捷键说明

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