SimpleResultSet

This class is a simple result set and meta data implementation. It can be used in Java functions that return a result set. Only the most basic methods are implemented, the others throw an exception. This implementation is standalone, and only relies on standard classes. It can be extended easily if required. An application can create a result set using the following code:
 SimpleResultSet rs = new SimpleResultSet();
 rs.addColumn("ID", Types.INTEGER, 10, 0);
 rs.addColumn("NAME", Types.VARCHAR, 255, 0);
 rs.addRow(new Object[] { new Integer(0), "Hello" });
 rs.addRow(new Object[] { new Integer(1), "World" });


Methods
void addColumn(String name, int sqlType, int precision, int scale)
Adds a column to the result set.
void addRow(Object[] row)
Add a new row to the result set.
void beforeFirst()
Moves the current position to before the first row, that means resets the result set.
void close()
Closes the result set and releases the resources.
int findColumn(String columnName)
Searches for a specific column in the result set.
Array getArray(int columnIndex)
Returns the value as a java.sql.Array.
Array getArray(String columnName)
Returns the value as a java.sql.Array.
BigDecimal getBigDecimal(int columnIndex)
Returns the value as a java.math.BigDecimal.
BigDecimal getBigDecimal(String columnName)
Returns the value as a java.math.BigDecimal.
boolean getBoolean(int columnIndex)
Returns the value as a boolean.
boolean getBoolean(String columnName)
Returns the value as a boolean.
byte getByte(int columnIndex)
Returns the value as a byte.
byte getByte(String columnName)
Returns the value as a byte.
byte[] getBytes(int columnIndex)
Returns the value as a byte array.
byte[] getBytes(String columnName)
Returns the value as a byte array.
String getCatalogName(int columnIndex)
Returns null.
String getColumnClassName(int columnIndex)
Returns null.
int getColumnCount()
Returns the column count.
int getColumnDisplaySize(int columnIndex)
Returns 15.
String getColumnLabel(int columnIndex)
Returns the column name.
String getColumnName(int columnIndex)
Returns the column name.
int getColumnType(int columnIndex)
Returns the SQL type.
String getColumnTypeName(int columnIndex)
Returns null.
int getConcurrency()
Returns ResultSet.CONCUR_READ_ONLY.
Date getDate(int columnIndex)
Returns the value as an java.sql.Date.
Date getDate(String columnName)
Returns the value as a java.sql.Date.
double getDouble(int columnIndex)
Returns the value as an double.
double getDouble(String columnName)
Returns the value as a double.
int getFetchDirection()
Returns ResultSet.FETCH_FORWARD.
int getFetchSize()
Returns 0.
float getFloat(int columnIndex)
Returns the value as a float.
float getFloat(String columnName)
Returns the value as a float.
int getHoldability()
Returns the current result set holdability.
int getInt(int columnIndex)
Returns the value as an int.
int getInt(String columnName)
Returns the value as an int.
long getLong(int columnIndex)
Returns the value as a long.
long getLong(String columnName)
Returns the value as a long.
ResultSetMetaData getMetaData()
Returns a reference to itself.
Object getObject(int columnIndex)
Returns the value as an Object.
Object getObject(String columnName)
Returns the value as an Object.
int getPrecision(int columnIndex)
Returns the precision.
int getRow()
Returns the row number (1, 2,...) or 0 for no row.
int getScale(int columnIndex)
Returns the scale.
String getSchemaName(int columnIndex)
Returns null.
short getShort(int columnIndex)
Returns the value as a short.
short getShort(String columnName)
Returns the value as a short.
Statement getStatement()
Returns null.
String getString(int columnIndex)
Returns the value as a String.
String getString(String columnName)
Returns the value as a String.
String getTableName(int columnIndex)
Returns null.
Time getTime(int columnIndex)
Returns the value as an java.sql.Time.
Time getTime(String columnName)
Returns the value as a java.sql.Time.
Timestamp getTimestamp(int columnIndex)
Returns the value as an java.sql.Timestamp.
Timestamp getTimestamp(String columnName)
Returns the value as a java.sql.Timestamp.
int getType()
Returns ResultSet.TYPE_FORWARD_ONLY.
SQLWarning getWarnings()
Returns null.
boolean isAutoIncrement(int columnIndex)
Returns false.
boolean isCaseSensitive(int columnIndex)
Returns true.
boolean isClosed()
Returns whether this result set has been closed.
boolean isCurrency(int columnIndex)
Returns false.
boolean isDefinitelyWritable(int columnIndex)
Returns false.
int isNullable(int columnIndex)
Returns ResultSetMetaData.columnNullableUnknown.
boolean isReadOnly(int columnIndex)
Returns true.
boolean isSearchable(int columnIndex)
Returns true.
boolean isSigned(int columnIndex)
Returns true.
boolean isWritable(int columnIndex)
Returns false.
boolean next()
Moves the cursor to the next row of the result set.
boolean wasNull()
Returns whether the last column accessed was null.

void addColumn(String name, int sqlType, int precision, int scale) throws SQLException

Adds a column to the result set.

Parameters:
name - null is replaced with C1, C2,...
sqlType - the value returned in getColumnType(..) (ignored internally)
precision - the precision
scale - the scale
Throws:
SQLException

void addRow(Object[] row) throws SQLException

Add a new row to the result set.

Parameters:
row - the row as an array of objects
Throws:
SQLException

void beforeFirst() throws SQLException

Moves the current position to before the first row, that means resets the result set.

Throws:
SQLException - is this method is not supported

void close()

Closes the result set and releases the resources.

int findColumn(String columnName) throws SQLException

Searches for a specific column in the result set. A case-insensitive search is made.

Parameters:
columnName - the name of the column label
Returns:
the column index (1,2,...)
Throws:
SQLException - if the column is not found or if the result set is closed

Array getArray(int columnIndex) throws SQLException

Returns the value as a java.sql.Array.

Returns:
the value
Throws:
SQLException

Array getArray(String columnName) throws SQLException

Returns the value as a java.sql.Array.

Returns:
the value
Throws:
SQLException

BigDecimal getBigDecimal(int columnIndex) throws SQLException

Returns the value as a java.math.BigDecimal.

Returns:
the value
Throws:
SQLException

BigDecimal getBigDecimal(String columnName) throws SQLException

Returns the value as a java.math.BigDecimal.

Returns:
the value
Throws:
SQLException

boolean getBoolean(int columnIndex) throws SQLException

Returns the value as a boolean.

Returns:
the value
Throws:
SQLException

boolean getBoolean(String columnName) throws SQLException

Returns the value as a boolean.

Returns:
the value
Throws:
SQLException

byte getByte(int columnIndex) throws SQLException

Returns the value as a byte.

Returns:
the value
Throws:
SQLException

byte getByte(String columnName) throws SQLException

Returns the value as a byte.

Returns:
the value
Throws:
SQLException

byte[] getBytes(int columnIndex) throws SQLException

Returns the value as a byte array.

Returns:
the value
Throws:
SQLException

byte[] getBytes(String columnName) throws SQLException

Returns the value as a byte array.

Returns:
the value
Throws:
SQLException

String getCatalogName(int columnIndex)

Returns null.

Returns:
null

String getColumnClassName(int columnIndex)

Returns null.

Returns:
null

int getColumnCount()

Returns the column count.

Returns:
the column count

int getColumnDisplaySize(int columnIndex)

Returns 15.

Returns:
15

String getColumnLabel(int columnIndex) throws SQLException

Returns the column name.

Returns:
the column name
Throws:
SQLException

String getColumnName(int columnIndex) throws SQLException

Returns the column name.

Returns:
the column name
Throws:
SQLException

int getColumnType(int columnIndex) throws SQLException

Returns the SQL type.

Returns:
the SQL type
Throws:
SQLException

String getColumnTypeName(int columnIndex)

Returns null.

Returns:
null

int getConcurrency()

Returns ResultSet.CONCUR_READ_ONLY.

Returns:
CONCUR_READ_ONLY

Date getDate(int columnIndex) throws SQLException

Returns the value as an java.sql.Date.

Returns:
the value
Throws:
SQLException

Date getDate(String columnName) throws SQLException

Returns the value as a java.sql.Date.

Returns:
the value
Throws:
SQLException

double getDouble(int columnIndex) throws SQLException

Returns the value as an double.

Returns:
the value
Throws:
SQLException

double getDouble(String columnName) throws SQLException

Returns the value as a double.

Returns:
the value
Throws:
SQLException

int getFetchDirection()

Returns ResultSet.FETCH_FORWARD.

Returns:
FETCH_FORWARD

int getFetchSize()

Returns 0.

Returns:
0

float getFloat(int columnIndex) throws SQLException

Returns the value as a float.

Returns:
the value
Throws:
SQLException

float getFloat(String columnName) throws SQLException

Returns the value as a float.

Returns:
the value
Throws:
SQLException

int getHoldability()

Returns the current result set holdability.

Returns:
the holdability

int getInt(int columnIndex) throws SQLException

Returns the value as an int.

Returns:
the value
Throws:
SQLException

int getInt(String columnName) throws SQLException

Returns the value as an int.

Returns:
the value
Throws:
SQLException

long getLong(int columnIndex) throws SQLException

Returns the value as a long.

Returns:
the value
Throws:
SQLException

long getLong(String columnName) throws SQLException

Returns the value as a long.

Returns:
the value
Throws:
SQLException

ResultSetMetaData getMetaData()

Returns a reference to itself.

Returns:
this

Object getObject(int columnIndex) throws SQLException

Returns the value as an Object.

Returns:
the value
Throws:
SQLException

Object getObject(String columnName) throws SQLException

Returns the value as an Object.

Returns:
the value
Throws:
SQLException

int getPrecision(int columnIndex) throws SQLException

Returns the precision.

Returns:
the precision
Throws:
SQLException

int getRow()

Returns the row number (1, 2,...) or 0 for no row.

Returns:
0

int getScale(int columnIndex) throws SQLException

Returns the scale.

Returns:
the scale
Throws:
SQLException

String getSchemaName(int columnIndex)

Returns null.

Returns:
null

short getShort(int columnIndex) throws SQLException

Returns the value as a short.

Returns:
the value
Throws:
SQLException

short getShort(String columnName) throws SQLException

Returns the value as a short.

Returns:
the value
Throws:
SQLException

Statement getStatement()

Returns null.

Returns:
null

String getString(int columnIndex) throws SQLException

Returns the value as a String.

Returns:
the value
Throws:
SQLException

String getString(String columnName) throws SQLException

Returns the value as a String.

Returns:
the value
Throws:
SQLException

String getTableName(int columnIndex)

Returns null.

Returns:
null

Time getTime(int columnIndex) throws SQLException

Returns the value as an java.sql.Time.

Returns:
the value
Throws:
SQLException

Time getTime(String columnName) throws SQLException

Returns the value as a java.sql.Time.

Returns:
the value
Throws:
SQLException

Timestamp getTimestamp(int columnIndex) throws SQLException

Returns the value as an java.sql.Timestamp.

Returns:
the value
Throws:
SQLException

Timestamp getTimestamp(String columnName) throws SQLException

Returns the value as a java.sql.Timestamp.

Returns:
the value
Throws:
SQLException

int getType()

Returns ResultSet.TYPE_FORWARD_ONLY.

Returns:
TYPE_FORWARD_ONLY

SQLWarning getWarnings()

Returns null.

Returns:
null

boolean isAutoIncrement(int columnIndex)

Returns false.

Returns:
false

boolean isCaseSensitive(int columnIndex)

Returns true.

Returns:
true

boolean isClosed()

Returns whether this result set has been closed.

Returns:
true if the result set was closed

boolean isCurrency(int columnIndex)

Returns false.

Returns:
false

boolean isDefinitelyWritable(int columnIndex)

Returns false.

Returns:
false

int isNullable(int columnIndex)

Returns ResultSetMetaData.columnNullableUnknown.

Returns:
columnNullableUnknown

boolean isReadOnly(int columnIndex)

Returns true.

Returns:
true

boolean isSearchable(int columnIndex)

Returns true.

Returns:
true

boolean isSigned(int columnIndex)

Returns true.

Returns:
true

boolean isWritable(int columnIndex)

Returns false.

Returns:
false

boolean next() throws SQLException

Moves the cursor to the next row of the result set.

Returns:
true if successful, false if there are no more rows
Throws:
SQLException

boolean wasNull()

Returns whether the last column accessed was null.

Returns:
true if the last column accessed was null