SimpleResultSetThis 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" });
void addColumn(String name, int sqlType, int precision, int scale) throws SQLExceptionAdds 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 SQLExceptionAdd a new row to the result set.Parameters:
row - the row as an array of objects
Throws:
SQLException
void beforeFirst() throws SQLExceptionMoves 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 SQLExceptionSearches 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 SQLExceptionReturns the value as a java.sql.Array.Returns:
the value
Throws:
SQLException
Array getArray(String columnName) throws SQLExceptionReturns the value as a java.sql.Array.Returns:
the value
Throws:
SQLException
BigDecimal getBigDecimal(int columnIndex) throws SQLExceptionReturns the value as a java.math.BigDecimal.Returns:
the value
Throws:
SQLException
BigDecimal getBigDecimal(String columnName) throws SQLExceptionReturns the value as a java.math.BigDecimal.Returns:
the value
Throws:
SQLException
boolean getBoolean(int columnIndex) throws SQLExceptionReturns the value as a boolean.Returns:
the value
Throws:
SQLException
boolean getBoolean(String columnName) throws SQLExceptionReturns the value as a boolean.Returns:
the value
Throws:
SQLException
byte getByte(int columnIndex) throws SQLExceptionReturns the value as a byte.Returns:
the value
Throws:
SQLException
byte getByte(String columnName) throws SQLExceptionReturns the value as a byte.Returns:
the value
Throws:
SQLException
byte[] getBytes(int columnIndex) throws SQLExceptionReturns the value as a byte array.Returns:
the value
Throws:
SQLException
byte[] getBytes(String columnName) throws SQLExceptionReturns 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 SQLExceptionReturns the column name.Returns:
the column name
Throws:
SQLException
String getColumnName(int columnIndex) throws SQLExceptionReturns the column name.Returns:
the column name
Throws:
SQLException
int getColumnType(int columnIndex) throws SQLExceptionReturns 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 SQLExceptionReturns the value as an java.sql.Date.Returns:
the value
Throws:
SQLException
Date getDate(String columnName) throws SQLExceptionReturns the value as a java.sql.Date.Returns:
the value
Throws:
SQLException
double getDouble(int columnIndex) throws SQLExceptionReturns the value as an double.Returns:
the value
Throws:
SQLException
double getDouble(String columnName) throws SQLExceptionReturns 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 SQLExceptionReturns the value as a float.Returns:
the value
Throws:
SQLException
float getFloat(String columnName) throws SQLExceptionReturns 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 SQLExceptionReturns the value as an int.Returns:
the value
Throws:
SQLException
int getInt(String columnName) throws SQLExceptionReturns the value as an int.Returns:
the value
Throws:
SQLException
long getLong(int columnIndex) throws SQLExceptionReturns the value as a long.Returns:
the value
Throws:
SQLException
long getLong(String columnName) throws SQLExceptionReturns the value as a long.Returns:
the value
Throws:
SQLException
ResultSetMetaData getMetaData()Returns a reference to itself.Returns:
this
Object getObject(int columnIndex) throws SQLExceptionReturns the value as an Object.Returns:
the value
Throws:
SQLException
Object getObject(String columnName) throws SQLExceptionReturns the value as an Object.Returns:
the value
Throws:
SQLException
int getPrecision(int columnIndex) throws SQLExceptionReturns 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 SQLExceptionReturns the scale.Returns:
the scale
Throws:
SQLException
String getSchemaName(int columnIndex)Returns null.Returns:
null
short getShort(int columnIndex) throws SQLExceptionReturns the value as a short.Returns:
the value
Throws:
SQLException
short getShort(String columnName) throws SQLExceptionReturns the value as a short.Returns:
the value
Throws:
SQLException
Statement getStatement()Returns null.Returns:
null
String getString(int columnIndex) throws SQLExceptionReturns the value as a String.Returns:
the value
Throws:
SQLException
String getString(String columnName) throws SQLExceptionReturns the value as a String.Returns:
the value
Throws:
SQLException
String getTableName(int columnIndex)Returns null.Returns:
null
Time getTime(int columnIndex) throws SQLExceptionReturns the value as an java.sql.Time.Returns:
the value
Throws:
SQLException
Time getTime(String columnName) throws SQLExceptionReturns the value as a java.sql.Time.Returns:
the value
Throws:
SQLException
Timestamp getTimestamp(int columnIndex) throws SQLExceptionReturns the value as an java.sql.Timestamp.Returns:
the value
Throws:
SQLException
Timestamp getTimestamp(String columnName) throws SQLExceptionReturns 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 SQLExceptionMoves 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
|