The
Rowset object
stores rows of filtered records in a flat format. It can store any kind of data
from any database that your report can access. This example shows you how to
navigate through the records stored in a rowset.
Create a
RowsetMetaData object and set
its result fields.
IRowsetMetaData rowsetMetaData = new RowsetMetaData();
Fields<IField> resultFields = rcd.getDataDefinition().getResultFields();
rowsetMetaData.setDataFields(resultFields);
Use the
RowsetController object to
create a
RowsetCursor
object.
RowsetController rowsetController = rcd.getRowsetController();
int batchSize = 100;
rowsetController.setRowsetBatchSize(batchSize);
RowsetCursor rowsetCursor = rowsetController.createCursor(null, rowsetMetaData);
Iterate through the records using the
moveNext
method.
while (!rowsetCursor.isEOF())
{
Record record = rowsetCursor.getCurrentRecord();
for (int i = 0; i < record.size(); i++)
{
String value = record.getValue(i);
//...
}
rowsetCursor.moveNext();
}Note: Use the
isEOF
method to check that you do not go out of bounds. If
isTotalRecordKnown is set to
false, the
getRecordCount method may
return inaccurate data.
Example:
This sample iterates through all the records in a
report, and then it formats the values as an HTML table and returns it in a
String object.
String navigateRowsets(ReportClientDocument rcd) throws ReportSDKException
{
IRowsetMetaData rowsetMetaData = new RowsetMetaData();
Fields<IField> resultFields = rcd.getDataDefinition().getResultFields();
rowsetMetaData.setDataFields(resultFields);
RowsetController rowsetController = rcd.getRowsetController();
int batchSize = 100;
rowsetController.setRowsetBatchSize(batchSize);
RowsetCursor rowsetCursor = rowsetController.createCursor(null, rowsetMetaData);
String rowsetString ="<table> <tr>";
Iterator<IField> it = resultFields.iterator();
while (it.hasNext())
{
IField field = it.next();
rowsetString += "<td>" + field.getName() + "</td>";
}
rowsetString += "<td>record number</td>";
rowsetString +="</tr>";
while (!rowsetCursor.isEOF())
{
rowsetString +="<tr>";
Record record = rowsetCursor.getCurrentRecord();
for (int i = 0; i < record.size(); i++)
{
rowsetString +="<td>";
rowsetString += record.getValue(i);
rowsetString += "</td>";
}
rowsetCursor.moveNext();
rowsetString +="\n";
}
rowsetString +="</table>";
return rowsetString;
} This list includes the classes used by the sample
code:
com.crystaldecisions.sdk.occa.report.application.ReportClientDocument
com.crystaldecisions.sdk.occa.report.application.RowsetController
com.crystaldecisions.sdk.occa.report.application.RowsetCursor
com.crystaldecisions.sdk.occa.report.data.Field
com.crystaldecisions.sdk.occa.report.data.Fields
com.crystaldecisions.sdk.occa.report.data.IField
com.crystaldecisions.sdk.occa.report.data.IRowsetMetaData
com.crystaldecisions.sdk.occa.report.data.Record
com.crystaldecisions.sdk.occa.report.data.RowsetMetaData
com.crystaldecisions.sdk.occa.report.lib.ReportSDKException
java.util.Iterator