FileDocCategorySizeDatePackage
Row.javaAPI DocExample12458Thu Jun 28 16:14:16 BST 2001com.ora.jsp.sql

Row

public class Row extends Object
This class represents a Row in a database query result. It contains a collection of Column objects. A Vector is used to hold the Column objects to preserve the column order in the base ResultSet.
author
Hans Bergsten, Gefion software
version
1.0

Fields Summary
private Column[]
columns
Constructors Summary
public Row(ResultSet rs)
Constructor. Reads the columns from the current row in the specified ResultSet and creates the corresponding ColumnValue objects.

param
rs the ResultSet
exception
SQLException, if thrown by any JDBC API call

        ResultSetMetaData rsmd = rs.getMetaData();
        int cols = rsmd.getColumnCount();
        columns = new Column[cols];
        // Note! Columns are numbered from 1 in the ResultSet
        for (int i = 1; i <= cols; i++) {
            int type = rsmd.getColumnType(i);
            switch (type) {
                case Types.DATE:
                    columns[i - 1] = new DateColumn(rsmd.getColumnName(i),
                        rs.getDate(i));
                    break;
                case Types.TIME:
                    columns[i - 1] = new TimeColumn(rsmd.getColumnName(i),
                        rs.getTime(i));
                    break;
                case Types.TIMESTAMP:
                    columns[i - 1] = new TimestampColumn(rsmd.getColumnName(i),
                        rs.getTimestamp(i));
                    break;
                case Types.REAL:
                case Types.FLOAT:
                    columns[i - 1] = new FloatColumn(rsmd.getColumnName(i),
                        rs.getFloat(i));
                    break;
                case Types.DOUBLE:
                    columns[i - 1] = new DoubleColumn(rsmd.getColumnName(i),
                        rs.getDouble(i));
                    break;
                case Types.TINYINT:
                    columns[i - 1] = new ByteColumn(rsmd.getColumnName(i),
                        rs.getByte(i));
                    break;
                case Types.SMALLINT:
                    columns[i - 1] = new ShortColumn(rsmd.getColumnName(i),
                        rs.getShort(i));
                    break;
                case Types.INTEGER:
                    columns[i - 1] = new IntColumn(rsmd.getColumnName(i),
                        rs.getInt(i));
                    break;
                case Types.BIGINT:
                    columns[i - 1] = new LongColumn(rsmd.getColumnName(i),
                        rs.getLong(i));
                    break;
                case Types.DECIMAL:
                case Types.NUMERIC:
                    columns[i - 1] = new BigDecimalColumn(rsmd.getColumnName(i),
                        rs.getBigDecimal(i, rsmd.getScale(i)));
                    break;
                case Types.CHAR:
                case Types.LONGVARCHAR:
                case Types.VARCHAR:
                    columns[i - 1] = new StringColumn(rsmd.getColumnName(i),
                        rs.getString(i));
                    break;
                default:
                    throw new UnsupportedTypeException("Unsupported SQL " +
                        "data type: " + type);
            }
        }
    
Methods Summary
public java.math.BigDecimalgetBigDecimal(int columnIndex)

        Column col = null;
        try {
            col = columns[columnIndex - 1];
        }
        catch (ArrayIndexOutOfBoundsException e) {
            throw new NoSuchColumnException(String.valueOf(columnIndex));
        }
        return col.getBigDecimal();
    
public java.math.BigDecimalgetBigDecimal(java.lang.String columnName)

        return getBigDecimal(getIndex(columnName));
    
public booleangetBoolean(int columnIndex)

        Column col = null;
        try {
            col = columns[columnIndex - 1];
        }
        catch (ArrayIndexOutOfBoundsException e) {
            throw new NoSuchColumnException(String.valueOf(columnIndex));
        }
        return col.getBoolean();
    
public booleangetBoolean(java.lang.String columnName)

        return getBoolean(getIndex(columnName));
    
public bytegetByte(int columnIndex)

        Column col = null;
        try {
            col = columns[columnIndex - 1];
        }
        catch (ArrayIndexOutOfBoundsException e) {
            throw new NoSuchColumnException(String.valueOf(columnIndex));
        }
        return col.getByte();
    
public bytegetByte(java.lang.String columnName)

        return getByte(getIndex(columnName));
    
public byte[]getBytes(int columnIndex)

        Column col = null;
        try {
            col = columns[columnIndex - 1];
        }
        catch (ArrayIndexOutOfBoundsException e) {
            throw new NoSuchColumnException(String.valueOf(columnIndex));
        }
        return col.getBytes();
    
public byte[]getBytes(java.lang.String columnName)

        return getBytes(getIndex(columnName));
    
public intgetColumnCount()
Returns the number of columns in this row.

        return columns.length;
    
public Column[]getColumns()
Returns an array of the Columns in this row.

        return columns;
    
public java.sql.DategetDate(int columnIndex)

        Column col = null;
        try {
            col = columns[columnIndex - 1];
        }
        catch (ArrayIndexOutOfBoundsException e) {
            throw new NoSuchColumnException(String.valueOf(columnIndex));
        }
        return col.getDate();
    
public java.sql.DategetDate(java.lang.String columnName)

        return getDate(getIndex(columnName));
    
public doublegetDouble(int columnIndex)

        Column col = null;
        try {
            col = columns[columnIndex - 1];
        }
        catch (ArrayIndexOutOfBoundsException e) {
            throw new NoSuchColumnException(String.valueOf(columnIndex));
        }
        return col.getDouble();
    
public doublegetDouble(java.lang.String columnName)

        return getDouble(getIndex(columnName));
    
public floatgetFloat(int columnIndex)

        Column col = null;
        try {
            col = columns[columnIndex - 1];
        }
        catch (ArrayIndexOutOfBoundsException e) {
            throw new NoSuchColumnException(String.valueOf(columnIndex));
        }
        return col.getFloat();
    
public floatgetFloat(java.lang.String columnName)

        return getFloat(getIndex(columnName));
    
private intgetIndex(java.lang.String columnName)
Returns the index of the column with the specified name, ignoring case since column names must be unique anyway and some databases ignores the case used in the SELECT statement when they create the ResultSet.

        for (int i = 0; i < columns.length; i++) {
            Column col = columns[i];
            if (col.getName().equalsIgnoreCase(columnName)) {
                // Adjust to 1 based indexed
                return i + 1;
            }
        }
        throw new NoSuchColumnException(columnName);
    
public intgetInt(int columnIndex)

        Column col = null;
        try {
            col = columns[columnIndex - 1];
        }
        catch (ArrayIndexOutOfBoundsException e) {
            throw new NoSuchColumnException(String.valueOf(columnIndex));
        }
        return col.getInt();
    
public intgetInt(java.lang.String columnName)

        return getInt(getIndex(columnName));
    
public longgetLong(int columnIndex)

        Column col = null;
        try {
            col = columns[columnIndex - 1];
        }
        catch (ArrayIndexOutOfBoundsException e) {
            throw new NoSuchColumnException(String.valueOf(columnIndex));
        }
        return col.getLong();
    
public longgetLong(java.lang.String columnName)

        return getLong(getIndex(columnName));
    
public java.lang.ObjectgetObject(int columnIndex)

        Column col = null;
        try {
            col = columns[columnIndex - 1];
        }
        catch (ArrayIndexOutOfBoundsException e) {
            throw new NoSuchColumnException(String.valueOf(columnIndex));
        }
        return col.getObject();
    
public java.lang.ObjectgetObject(java.lang.String columnName)

        return getObject(getIndex(columnName));
    
public shortgetShort(int columnIndex)

        Column col = null;
        try {
            col = columns[columnIndex - 1];
        }
        catch (ArrayIndexOutOfBoundsException e) {
            throw new NoSuchColumnException(String.valueOf(columnIndex));
        }
        return col.getShort();
    
public shortgetShort(java.lang.String columnName)

        return getShort(getIndex(columnName));
    
public java.lang.StringgetString(int columnIndex)

        Column col = null;
        try {
            col = columns[columnIndex - 1];
        }
        catch (ArrayIndexOutOfBoundsException e) {
            throw new NoSuchColumnException(String.valueOf(columnIndex));
        }
        return col.getString();
    
public java.lang.StringgetString(java.lang.String columnName)

        return getString(getIndex(columnName));
    
public java.sql.TimegetTime(int columnIndex)

        Column col = null;
        try {
            col = columns[columnIndex - 1];
        }
        catch (ArrayIndexOutOfBoundsException e) {
            throw new NoSuchColumnException(String.valueOf(columnIndex));
        }
        return col.getTime();
    
public java.sql.TimegetTime(java.lang.String columnName)

        return getTime(getIndex(columnName));
    
public java.sql.TimestampgetTimestamp(int columnIndex)

        Column col = null;
        try {
            col = columns[columnIndex - 1];
        }
        catch (ArrayIndexOutOfBoundsException e) {
            throw new NoSuchColumnException(String.valueOf(columnIndex));
        }
        return col.getTimestamp();
    
public java.sql.TimestampgetTimestamp(java.lang.String columnName)

        return getTimestamp(getIndex(columnName));