litebase
Class ResultSet

java.lang.Object
  extended by litebase.ResultSet

public class ResultSet
extends java.lang.Object

This class represents a set or rows resulting from a LitebaseConnection.executeQuery() method call. Here's an example:

 ResultSet rs = driver.executeQuery("select name, salary, age from person");
 while (rs.next())
    Vm.debug(pad(rs.getString("name"), 32) + pad(rs.getString("salary"), 16) 
                                                     + rs.getInt("age") + " years");
 
Result sets cannot be constructed directly; instead, you must issue a sql to the driver.


Constructor Summary
ResultSet()
           
 
Method Summary
 boolean absolute(int row)
          Places this result set cursor at the given absolute row.
 void afterLast()
          Places the cursor after the last record.
 void beforeFirst()
          Places the cursor before the first record.
 void close()
          Closes a result set.
 boolean first()
          Places the cursor in the first record of the result set.
 byte[] getBlob(int colIdx)
          Given the column index (starting from 1), returns a byte (blob) array that is represented by this column.
 byte[] getBlob(java.lang.String colName)
          Given the column name (case insensitive), returns a byte array (blob) that is represented by this column.
 char[] getChars(int colIdx)
          Given the column index (starting from 1), returns a char array that is represented by this column.
 char[] getChars(java.lang.String colName)
          Given the column name (case insensitive), returns a char array that is represented by this column.
 totalcross.util.Date getDate(int colIdx)
          Given the column index (starting from 1), returns a Date value that is represented by this column.
 totalcross.util.Date getDate(java.lang.String colName)
          Given the column name (case insensitive), returns a Date value that is represented by this column.
 totalcross.sys.Time getDateTime(int colIdx)
          Given the column index (starting from 1), returns a Time (correspondent to a DATETIME data type) value that is represented by this column.
 totalcross.sys.Time getDateTime(java.lang.String colName)
          Given the column name (case insensitive), returns a Time (correspondent to a DATETIME data type) value that is represented by this column.
 double getDouble(int colIdx)
          Given the column index (starting from 1), returns a double value that is represented by this column.
 double getDouble(java.lang.String colName)
          Given the column name (case insensitive), returns a double value that is represented by this column.
 double getFloat(int colIdx)
          Given the column index (starting from 1), returns a float value that is represented by this column.
 double getFloat(java.lang.String colName)
          Given the column name (case insensitive), returns a float value that is represented by this column.
 int getInt(int colIdx)
          Given the column index (starting from 1), returns an integer value that is represented by this column.
 int getInt(java.lang.String colName)
          Given the column name (case insensitive), returns an integer value that is represented by this column.
 long getLong(int colIdx)
          Given the column index (starting from 1), returns a long value that is represented by this column.
 long getLong(java.lang.String colName)
          Given the column name (case insensitive), returns a long value that is represented by this column.
 ResultSetMetaData getResultSetMetaData()
          Returns the meta data for this result set.
 int getRow()
          Returns the current physical row of the table where the cursor is.
 int getRowCount()
          Returns the number of rows of the result set.
 short getShort(int colIdx)
          Given the column index (starting from 1), returns a short value that is represented by this column.
 short getShort(java.lang.String colName)
          Given the column name (case insensitive), returns a short value that is represented by this column.
 java.lang.String getString(int colIdx)
          Given the column index (starting from 1), returns a string that is represented by this column.
 java.lang.String getString(java.lang.String colName)
          Given the column name (case insensitive), returns a string that is represented by this column.
 java.lang.String[][] getStrings()
          Starting from the current cursor position, it reads all result set rows of the result set.
 java.lang.String[][] getStrings(int count)
          Starting from the current cursor position, it reads all result set rows that are being requested.
 boolean isNull(int colIdx)
          Given the column index (starting from 1), indicates if this column has a NULL.
 boolean isNull(java.lang.String colName)
          Given the column name (case insensitive), indicates if this column has a NULL.
 boolean last()
          Places the cursor in the last record of the result set.
 boolean next()
          Gets the next record of the result set.
 boolean prev()
          Returns the previous record of the result set.
 boolean relative(int rows)
          Moves the cursor rows in distance.
 void setDecimalPlaces(int col, int places)
          Sets the number of decimal places that the given column (starting from 1) will have when being converted to String.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResultSet

public ResultSet()
Method Detail

getResultSetMetaData

public ResultSetMetaData getResultSetMetaData()
                                       throws DriverException
Returns the meta data for this result set.

Returns:
The meta data for this result set.
Throws:
DriverException - If the result set is closed.

close

public void close()
Closes a result set. Releases all memory allocated for this object. Its a good idea to call this when you no longer needs it, but it is also called by the GC when the object is no longer in use.

Throws:
DriverException - if the result set is closed.

beforeFirst

public void beforeFirst()
                 throws DriverException
Places the cursor before the first record.

Throws:
DriverException - If the result set is closed.

afterLast

public void afterLast()
               throws DriverException
Places the cursor after the last record.

Throws:
DriverException - If the result set is closed.

first

public boolean first()
              throws DriverException
Places the cursor in the first record of the result set.

Returns:
true if it was possible to place the cursor in the first record; false, otherwise.
Throws:
DriverException - If the result set is closed.

last

public boolean last()
             throws DriverException
Places the cursor in the last record of the result set.

Returns:
true if it was possible to place the cursor in the last record; false, otherwise.
Throws:
DriverException - If the result set is closed.

next

public boolean next()
             throws DriverException
Gets the next record of the result set.

Returns:
true if there is a next record to go to in the result set; false, otherwise.
Throws:
DriverException - If the result set is closed or an IOException occurs.

prev

public boolean prev()
             throws DriverException
Returns the previous record of the result set.

Returns:
true if there is a previous record to go to in the result set; false, otherwise.
Throws:
DriverException - If the result set is closed or an IOException occurs.

getShort

public short getShort(int colIdx)
Given the column index (starting from 1), returns a short value that is represented by this column. Note that it is only possible to request this column as short if it was created with this precision.

Parameters:
colIdx - The column index.
Returns:
The column value; if the value is SQL NULL, the value returned is 0.

getShort

public short getShort(java.lang.String colName)
Given the column name (case insensitive), returns a short value that is represented by this column. Note that it is only possible to request this column as short if it was created with this precision. This method is slightly slower then the method that accepts a column index.

Parameters:
colName - The column name.
Returns:
The column value; if the value is SQL NULL, the value returned is 0.

getInt

public int getInt(int colIdx)
Given the column index (starting from 1), returns an integer value that is represented by this column. Note that it is only possible to request this column as integer if it was created with this precision.

Parameters:
colIdx - The column index.
Returns:
The column value; if the value is SQL NULL, the value returned is 0.

getInt

public int getInt(java.lang.String colName)
Given the column name (case insensitive), returns an integer value that is represented by this column. Note that it is only possible to request this column as integer if it was created with this precision. This method is slightly slower then the method that accepts a column index.

Parameters:
colName - The column name.
Returns:
The column value; if the value is SQL NULL, the value returned is 0.

getLong

public long getLong(int colIdx)
Given the column index (starting from 1), returns a long value that is represented by this column. Note that it is only possible to request this column as long if it was created with this precision.

Parameters:
colIdx - The column index.
Returns:
The column value; if the value is SQL NULL, the value returned is 0.

getLong

public long getLong(java.lang.String colName)
Given the column name (case insensitive), returns a long value that is represented by this column. Note that it is only possible to request this column as long if it was created with this precision. This method is slightly slower then the method that accepts a column index.

Parameters:
colName - The column name.
Returns:
The column value; if the value is SQL NULL, the value returned is 0.

getFloat

public double getFloat(int colIdx)
Given the column index (starting from 1), returns a float value that is represented by this column. Note that it is only possible to request this column as float if it was created with this precision.

Parameters:
colIdx - The column index.
Returns:
The column value; if the value is SQL NULL, the value returned is 0.0.

getFloat

public double getFloat(java.lang.String colName)
Given the column name (case insensitive), returns a float value that is represented by this column. Note that it is only possible to request t his column as float if it was created with this precision. This method is slightly slower then the method that accepts a column index.

Parameters:
colName - The column name.
Returns:
The column value; if the value is SQL NULL, the value returned is 0.0.

getDouble

public double getDouble(int colIdx)
Given the column index (starting from 1), returns a double value that is represented by this column. Note that it is only possible to request this column as double if it was created with this precision.

Parameters:
colIdx - The column index.
Returns:
The column value; if the value is SQL NULL, the value returned is 0.0.

getDouble

public double getDouble(java.lang.String colName)
Given the column name (case insensitive), returns a double value that is represented by this column. Note that it is only possible to request this column as double if it was created with this precision. This method is slightly slower then the method that accepts a column index.

Parameters:
colName - The column name.
Returns:
The column value; if the value is SQL NULL, the value returned is 0.0.

getChars

public char[] getChars(int colIdx)
Given the column index (starting from 1), returns a char array that is represented by this column. Note that it is only possible to request this column as a char array if it was created as a string.

Parameters:
colIdx - The column index.
Returns:
The column value; if the value is SQL NULL, the value returned is null.

getChars

public char[] getChars(java.lang.String colName)
Given the column name (case insensitive), returns a char array that is represented by this column. Note that it is only possible to request this column as a char array if it was created as a string. This method is slightly slower then the method that accepts a column index.

Parameters:
colName - The column name.
Returns:
The column value; if the value is SQL NULL, the value returned is null.

getBlob

public byte[] getBlob(int colIdx)
Given the column index (starting from 1), returns a byte (blob) array that is represented by this column. Note that it is only possible to request this column as a blob if it was created this way.

Parameters:
colIdx - the column index.
Returns:
the column value; if the value is SQL NULL, the value returned is null.

getBlob

public byte[] getBlob(java.lang.String colName)
Given the column name (case insensitive), returns a byte array (blob) that is represented by this column. Note that it is only possible to request this column as a blob if it was created this way. This method is slightly slower then the method that accepts a column index.

Parameters:
colName - The column name.
Returns:
The column value; if the value is SQL NULL, the value returned is null.

getString

public java.lang.String getString(int colIdx)
Given the column index (starting from 1), returns a string that is represented by this column. Any column type can be returned as a string. Double/float values formatting will use the precision set with the setDecimalPlaces() method.

Parameters:
colIdx - The column index.
Returns:
The column value; if the value is SQL NULL, the value returned is null

getString

public java.lang.String getString(java.lang.String colName)
Given the column name (case insensitive), returns a string that is represented by this column. Any column type can be returned as a string. Double/float values formatting will use the precision set with the setDecimalPlaces() method. This method is slightly slower then the method that accepts a column index.

Parameters:
colName - The column name.
Returns:
The column value; if the value is SQL NULL, the value returned is null

getStrings

public java.lang.String[][] getStrings(int count)
                                throws DriverException
Starting from the current cursor position, it reads all result set rows that are being requested. first(), last(), prev(), or next() must be used to set the current position, but not beforeFirst() or afterLast(). It doesn't return BLOB values. null is returned in their places instead.

Parameters:
count - The number of rows to be fetched, or -1 for all.
Returns:
A matrix, where String[0] is the first row, and String[0][0], String[0][1]... are the column elements of the first row. Returns null if there's no more element to be fetched. Double/float values will be formatted using setDecimalPlaces() settings. If the value is SQL NULL, the value returned is null.
Throws:
DriverException - If the result set is closed or an IOException occurs.
SQLParseException - If an InvalidDateException occurs.

getStrings

public java.lang.String[][] getStrings()
Starting from the current cursor position, it reads all result set rows of the result set. first(), last(), prev(), or next() must be used to set the current position, but not beforeFirst() or afterLast(). It doesn't return BLOB values. null is returned in their places instead.

Returns:
A matrix, where String[0] is the first row, and String[0][0], String[0][1]... are the column elements of the first row. Returns null if there's no more element to be fetched. Double/float values will be formatted using the setDecimalPlaces() settings. If the value is SQL NULL, the value returned is null.

getDate

public totalcross.util.Date getDate(int colIdx)
                             throws SQLParseException
Given the column index (starting from 1), returns a Date value that is represented by this column. Note that it is only possible to request this column as a date if it was created this way (DATE).

Parameters:
colIdx - The column index.
Returns:
The column value as a Date object; if the value is SQL NULL, the value returned is null.
Throws:
SQLParseException - If an InvalidDateException occurs.

getDate

public totalcross.util.Date getDate(java.lang.String colName)
                             throws DriverException
Given the column name (case insensitive), returns a Date value that is represented by this column. Note that it is only possible to request this column as a date if it was created this way (DATE). This method is slightly slower then the method that accepts a column index.

Parameters:
colName - The column name.
Returns:
The column value as a Date object; if the value is SQL NULL, the value returned is null.
Throws:
SQLParseException - If an InvalidDateException occurs.
DriverException

getDateTime

public totalcross.sys.Time getDateTime(int colIdx)
Given the column index (starting from 1), returns a Time (correspondent to a DATETIME data type) value that is represented by this column. Note that it is only possible to request this column as a datetime if it was created this way.

Parameters:
colIdx - The colum index, starting from 1.
Returns:
The column value as a Time object; if the DATETIME value is SQL NULL, the value returned is null.

getDateTime

public totalcross.sys.Time getDateTime(java.lang.String colName)
Given the column name (case insensitive), returns a Time (correspondent to a DATETIME data type) value that is represented by this column. Note that it is only possible to request this column as a datetime if it was created this way. This method is slightly slower then the method that accepts a column index.

Parameters:
colName - The colum name.
Returns:
The column value as a Time object; if the DATETIME value is SQL NULL, the value returned is null.

absolute

public boolean absolute(int row)
                 throws DriverException
Places this result set cursor at the given absolute row. This is the absolute physical row of the table. This method is usually used to restore the row at a previous row got with the getRow() method.

Parameters:
row - The row to set the cursor.
Returns:
true whenever this method does not throw an exception.
Throws:
DriverException - the result set is closed or an IOException occurs.

relative

public boolean relative(int rows)
                 throws DriverException
Moves the cursor rows in distance. The value can be greater or lower than zero.

Parameters:
rows - The distance to move the cursor.
Returns:
true whenever this method does not throw an exception.
Throws:
DriverException - If the result set is closed or an IOException occurs.

getRow

public int getRow()
           throws DriverException
Returns the current physical row of the table where the cursor is. It must be used with absolute() method.

Returns:
The current physical row of the table where the cursor is.
Throws:
DriverException - If the result set is closed.

setDecimalPlaces

public void setDecimalPlaces(int col,
                             int places)
                      throws DriverException
Sets the number of decimal places that the given column (starting from 1) will have when being converted to String.

Parameters:
col - The column.
places - The number of decimal places.
Throws:
DriverException - If the result set is closed, the column index is invalid, or the value for decimal places is invalid.

getRowCount

public int getRowCount()
                throws DriverException
Returns the number of rows of the result set.

Returns:
The number of rows.
Throws:
DriverException - If the result set is closed.

isNull

public boolean isNull(int colIdx)
               throws DriverException
Given the column index (starting from 1), indicates if this column has a NULL.

Parameters:
colIdx - The column index.
Returns:
true if the value is SQL NULL; false, otherwise.
Throws:
DriverException - If the result set is closed.

isNull

public boolean isNull(java.lang.String colName)
               throws DriverException
Given the column name (case insensitive), indicates if this column has a NULL.

Parameters:
colName - The column name.
Returns:
true if the value is SQL NULL; false, otherwise.
Throws:
DriverException - If the result set is closed or the column name is not found.