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

📄 tinysqlresultset.java

📁 jdbc 的实例源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        // 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.   *   */  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 preceision 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));  }    /**   *   * Get the long 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 long getLong(String columnName) throws SQLException {    return getLong(findColumn(columnName));  }  /**   *   * Get the float 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 float getFloat(String columnName) throws SQLException {      return getFloat(findColumn(columnName));  }  /**   *   * Get the double value of a named column   * @param columnName is the SQL name of the column   * @return the column value; if isNull the value is 0   *   */  public double getDouble(String columnName) throws SQLException {      return getDouble(findColumn(columnName));  }    /**   *   * Get the value of a named column as a BigDecimal object   * @param columnName is the SQL name of the column   * @return the column value; if isNull the value is null   *   */  public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException {      return getBigDecimal(findColumn(columnName), scale);  }  /**   *   * Get the value of a named column as a byte array   * @param columnName is the SQL name of the column   * @return the column value; if isNull the value is null   *   */  public byte[] getBytes(String columnName) throws SQLException {      return getBytes(findColumn(columnName));  }    /**   *   * Get a named column as a java.sql.Date    * @param columnName is the SQL name of the column   * @return the column value; if isNull the value is null   *   */  public java.sql.Date getDate(String columnName) throws SQLException {      return getDate(findColumn(columnName));      }    /**   *   * Get a named column as a java.sql.Time    * @param columnName is the SQL name of the column   * @return the column value; if isNull the value is null   *   */  public java.sql.Time getTime(String columnName) throws SQLException {    return getTime(findColumn(columnName));  }    /**   *   * Get a named column as a java.sql.Time    * @param columnName is the SQL name of the column   * @return the column value; if isNull the value is null   *   */  public java.sql.Timestamp getTimestamp(String columnName)       throws SQLException {    return getTimestamp(findColumn(columnName));  }    /**   *    * This is unsupported, but we'll try to call the corresponding   * call by column index.   *   */  public java.io.InputStream getAsciiStream(String columnName)       throws SQLException {    return getAsciiStream(findColumn(columnName));  }  /**   *    * This is unsupported, but we'll try to call the corresponding   * call by column index.   *   */  public java.io.InputStream getUnicodeStream(String columnName)       throws SQLException {    return getUnicodeStream(findColumn(columnName));  }  /**   *    * This is unsupported, but we'll try to call the corresponding   * call by column index.   *   */  public java.io.InputStream getBinaryStream(String columnName)       throws SQLException {    return getBinaryStream(findColumn(columnName));  }  /**   *   * Get the value of a named column as an object   * @param columnName the SQL column name   * @param sqlType SQL type code defined by java.sql.Types   * @return the parameter as an Object   *   */  public Object getObject(String columnName, int sqlType, int scale)       throws SQLException {    return getObject(findColumn(columnName), sqlType, scale);  }  /**   *   * Same as above, except defaulting scale to 0.   *   */  public Object getObject(String columnName, int type)       throws SQLException {    return getObject(findColumn(columnName), type, 0);  }  /**   *   * Same as above, except returning the default SQL type   *   */  public Object getObject(String columnName) throws SQLException {    return getObject(findColumn(columnName));  }    /**   *   * Given a column name, this method returns the column number for that   * name.  Column name to number mappings are kept inside a Hashtable.   * Applications that do not need the overhead of this calculation are   * not penalized since the mapping only occurs on the first attempt to   * access a column number by name.   * @exception java.sql.SQLException thrown if a bad name is passed   * @param name the name of the column desired   * @return the column number, 1 being the first column   *   */  public int findColumn(String name) throws SQLException {        Integer num;       // does the column map exist?    //    if( column_map == null ) {      int i, maxi;           // create a Hashtable which expects to hold      // enough objects for all the columns in the      // result set.      //      column_map = new Hashtable(maxi = result.numcols());      // add each column by name, with an Integer index      //      for(i=0; i<maxi; i++) {        tsColumn tsc = result.columnAtIndex(i);	column_map.put(tsc.name, new Integer(i));      }    }    // one way or another, we've got a column_map; either it    // already existed, or the above code created it.    //    // look up the column name in the map, and find it's    // index (the Integer object)    //    num = (Integer)column_map.get(name);    if( num == null ) {      throw new SQLException("Invalid column name: " + name);    }    // return the column index as an int    //    return num.intValue() + 1;  }  /**   *   * Return the warning chain. This is presently unsupported.   * @see java.sql.Statement#getWarnings   * @return the chain of warnings   *   */  public SQLWarning getWarnings() throws SQLException {    return null;  }  /**   *   * Clear the chain of warnings. This does nothing, since the   * warning chain is not used by tinySQL   * @see java.sql.Statement#clearWarnings   *   */  public void clearWarnings() throws SQLException {  }}

⌨️ 快捷键说明

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