{
log.log( this, "providing HTML table from DB transaction...");
// check transition
if( status != FINISHED_QUERY ){
throw new KExceptionClass(
"**** Query error **** \n" +
"Cannot provide HTML table from DB transaction. The status is not FINISHED_QUERY.", null
);
}
if( fetchComplete ){
throw new KExceptionClass(
"**** Query error **** \n" +
"SQL fetch past indicated end of data.", null );
}
StringBuffer buffer =
new StringBuffer( "<TABLE BORDER=1>\n" );
if( headingColor != null )
buffer.append(" <TR BGCOLOR=\"" + headingColor + "\"> \n " );
else
buffer.append(" <TR>\n " );
try {
//get query results
ResultSetMetaData metaData = resultSet.getMetaData();
for( int col=1; col<=columnCount; col++ ) {
//get headers
String colName = metaData.getColumnName(col).trim();
buffer.append( "<TH>" + colName );
}
//get rows
while( resultSet.next() ) {
buffer.append("\n <TR>\n " );
for( int col=1; col<=columnCount; col++ ) {
String cellData = resultSet.getString( col );
buffer.append("<TD>" + cellData );
}
}
}
catch( SQLException err ) {
String message = "Cannot provide HTML table.\n<br>" + err;
log.log( this, message + "SQLException: " + err );
throw new KExceptionClass( message, err );
}
buffer.append( "\n</TABLE>" );
fetchComplete = true;