com.hp.ucmdb.discovery.library.clients.query
Class ResultSet

java.lang.Object
  extended by com.hp.ucmdb.discovery.library.clients.query.ResultSet
Direct Known Subclasses:
DbResultSet, QueryResultSet

public abstract class ResultSet
extends java.lang.Object

ResultSet represents the result of a query run by QueryClient. The ResultSet class providews the APIs to iterate through the data and fetch data by name or index.
Here is example of using SNMPClient for disks discovery:


     client = Framework.getClientFactory(ClientsConsts.SNMP_PROTOCOL_NAME).createClient()
     data_name_mib = '1.3.6.1.2.1.25.2.3.1.3,1.3.6.1.2.1.25.2.3.1.4,string,1.3.6.1.2.1.25.2.3.1.5,double,1.3.6.1.2.1.25.2.3.1.6,string,1.3.6.1.2.1.25.2.3.1.7,string,1.3.6.1.2.1.25.2.3.1.2,string,1.3.6.1.2.1.25.2.3.1.4,string'
     resultSet = client.executeQuery(data_name_mib)
     while resultSet.next():
                        diskName = resultSet.getString(2)
                        diskSize = resultSet.getString(3)
                        diskType = resultSet.getString(6)

 
Before fetching data from the result set, check that there is data for processing. The next method also the next row in the result set to be the current row. There are two implementations for this class:DbResultSet and QueryResultSet. The methods with named columns as arguments, for example getString(String column name) are implemented only in the DbResultSet class. Close a ResultSet in your code when no further processing is required on the set.

See Also:
DbResultSet, QueryResultSet

Constructor Summary
ResultSet(QueryClient client)
           
 
Method Summary
abstract  java.lang.String[][] asTable()
          Returns the entire RecordSet
abstract  void close()
          Closes the ResultSet.
 boolean first()
          Sets the first row in the ResultSet to be the active record.
 boolean getBoolean(int column)
          Returns the value of the boolean column specified by the column index.
 boolean getBoolean(java.lang.String name)
          Returns the value of the boolean column specified by the column name.
 java.util.Date getDate(int column)
          Returns the value of the column specified by the column index.
 java.util.Date getDate(java.lang.String name)
          Returns the value of the column specified by the column name.
 double getDouble(int column)
          Returns the value of the column specified by the column name.
 double getDouble(java.lang.String name)
          Returns the value of the column specified by the column name.
 float getFloat(int column)
          Returns the value of the column specified by the column index.
 float getFloat(java.lang.String name)
          Returns the value of the column specified by the column name.
 int getInt(int column)
          Returns the value of the column specified by the column index.
 int getInt(java.lang.String name)
          Returns the value of the column specified by the column name.
 long getLong(int column)
          Returns the value of the column specified by the column index.
 long getLong(java.lang.String name)
          Returns the value of the column specified by the column name.
 java.lang.String getString(int column)
          Returns the value of the specifed column in the current row.
 java.lang.String getString(java.lang.String name)
          Returns the value of column specified by the column name.
 java.sql.Timestamp getTimestamp(int column)
          Returns the value of the column specified by the column index.
 java.sql.Timestamp getTimestamp(java.lang.String name)
          Returns the value of the column specified by the column name.
 boolean next()
          Sets the next row in the ResultSet to be the active record.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResultSet

public ResultSet(QueryClient client)
Method Detail

getString

public java.lang.String getString(int column)
                           throws java.lang.Exception
Returns the value of the specifed column in the current row.
If the data cannot be returned as a string, an exception is thrown.

Parameters:
column - The column index (1-based)
Returns:
The string representation of the value of the specified column in the current row
Throws:
java.lang.Exception

getString

public java.lang.String getString(java.lang.String name)
                           throws java.lang.Exception
Returns the value of column specified by the column name.
If the data cannot be returned as a string, an exception is thrown.

Parameters:
name - The column name
Returns:
The string representation of the value of the specified column in the current row
Throws:
java.lang.Exception

getBoolean

public boolean getBoolean(int column)
                   throws java.lang.Exception
Returns the value of the boolean column specified by the column index.
If the data cannot be returned as a boolean value, an exception is thrown.

Parameters:
column - The column index (1-based)
Returns:
The boolean value of the specified column in the current row
Throws:
java.lang.Exception

getBoolean

public boolean getBoolean(java.lang.String name)
                   throws java.lang.Exception
Returns the value of the boolean column specified by the column name.
If the data cannot be returned as a boolean value, an exception is thrown.

Parameters:
name - The column name (1-based)
Returns:
The boolean value of the specified column in the current row
Throws:
java.lang.Exception

getInt

public int getInt(int column)
           throws java.lang.Exception
Returns the value of the column specified by the column index.
If the data cannot be returned as an integer value, an exception is thrown.

Parameters:
column - The column index (1-based)
Returns:
The integer value of the designated column in the current row
Throws:
java.lang.Exception

getInt

public int getInt(java.lang.String name)
           throws java.lang.Exception
Returns the value of the column specified by the column name.
If the data cannot be returned as an integer value, an exception is thrown.

Parameters:
name - The column name
Returns:
The integer value of the designated column in the current row
Throws:
java.lang.Exception

getLong

public long getLong(int column)
             throws java.lang.Exception
Returns the value of the column specified by the column index.
If the data cannot be returned as an long integer value, an exception is thrown.

Parameters:
column - The column index (1-based)
Returns:
The long value of the designated column in the current row
Throws:
java.lang.Exception

getLong

public long getLong(java.lang.String name)
             throws java.lang.Exception
Returns the value of the column specified by the column name.
If the data cannot be returned as an long integer value, an exception is thrown.

Parameters:
name - The column name
Returns:
The long value of the designated column in the current row
Throws:
java.lang.Exception

getDouble

public double getDouble(int column)
                 throws java.lang.Exception
Returns the value of the column specified by the column name.
If the data cannot be returned as an double value, an exception is thrown.

Parameters:
column - column index (1-based)
Returns:
The value of the designated column in the current row as a long
Throws:
java.lang.Exception

getDouble

public double getDouble(java.lang.String name)
                 throws java.lang.Exception
Returns the value of the column specified by the column name.
If the data cannot be returned as an double value, an exception is thrown.

Parameters:
column - column index (1-based)
Returns:
The value of the designated column in the current row as a long
Throws:
java.lang.Exception

getFloat

public float getFloat(int column)
               throws java.lang.Exception
Returns the value of the column specified by the column index.
If the data cannot be returned as an float value, an exception is thrown.

Parameters:
column - column index (1-based)
Returns:
The value of the designated column in the current row as a float
Throws:
java.lang.Exception

getFloat

public float getFloat(java.lang.String name)
               throws java.lang.Exception
Returns the value of the column specified by the column name.
If the data cannot be returned as an float value, an exception is thrown.

Parameters:
name - The column name
Returns:
The value of the designated column in the current row as a float
Throws:
java.lang.Exception

getTimestamp

public java.sql.Timestamp getTimestamp(int column)
                                throws java.lang.Exception
Returns the value of the column specified by the column index.
If the data cannot be returned as a timestamp, an exception is thrown.

Parameters:
column - column index (1-based)
Returns:
The value of the designated column in the current row as a Timestamp
Throws:
java.lang.Exception

getTimestamp

public java.sql.Timestamp getTimestamp(java.lang.String name)
                                throws java.lang.Exception
Returns the value of the column specified by the column name.
If the data cannot be returned as a timestamp, an exception is thrown.

Parameters:
name - The column name
Returns:
The value of the designated column in the current row as a Timestamp
Throws:
java.lang.Exception

getDate

public java.util.Date getDate(int column)
                       throws java.lang.Exception
Returns the value of the column specified by the column index.
If the data cannot be returned as a date, an exception is thrown.

Parameters:
column - column index (1-based)
Returns:
The value of the designated column in the current row as a Date
Throws:
java.lang.Exception

getDate

public java.util.Date getDate(java.lang.String name)
                       throws java.lang.Exception
Returns the value of the column specified by the column name.
If the data cannot be returned as a date, an exception is thrown.

Parameters:
name - The column name
Returns:
The value of the designated column in the current row as a Date
Throws:
java.lang.Exception

next

public boolean next()
             throws java.lang.Exception
Sets the next row in the ResultSet to be the active record.

Returns:
true on success
Throws:
java.lang.Exception

first

public boolean first()
              throws java.lang.Exception
Sets the first row in the ResultSet to be the active record.

Returns:
true on success
Throws:
java.lang.Exception

close

public abstract void close()
                    throws java.lang.Exception
Closes the ResultSet. Caution: You must call close when finished working with a record set that was returned from a database.

Throws:
java.lang.Exception

asTable

public abstract java.lang.String[][] asTable()
                                      throws java.lang.Exception
Returns the entire RecordSet

Returns:
The query result as an array representing the rows where each row element contains an array of column values.
Throws:
java.lang.Exception


Documentation Feedback
Copyright 2010 Hewlett-Packard Development Company, L.P.