1 package nmp.dbms.util; 2 3 import java.io.*; 4 import nmp.dbms.*; 5 6 public class Utilities 7 { 8 /*** 9 * Displays a result set with column separated by a tab 10 */ 11 public static void displayResultSet( PrintStream ps, SQLVectorResult result) { 12 PrintWriter pw = new PrintWriter( ps); 13 displayResultSet( pw, result); 14 pw.flush(); 15 } 16 17 public static void displayResultSet( PrintWriter pw, SQLVectorResult result) { 18 if( result == null || result.rows == null || result.columnName == null) 19 pw.println( "Internal error"); 20 for( int i = 0; i < result.columnName.length; i++) 21 pw.print( result.columnName[i] + "\t"); 22 pw.println(); 23 for( int i = 0; i < result.rows.size(); i++) { 24 Object[] row = (Object[])result.rows.elementAt( i); 25 for( int j = 0; j < row.length; j++) { 26 if( row[j] == null) 27 pw.print( "null\t"); 28 else 29 pw.print( row[j].toString() + "\t"); 30 } 31 pw.println(); 32 } 33 } 34 35 /*** 36 * Displays a result in a HTML table 37 */ 38 public static void displayHTMLResultSet( PrintStream ps, SQLVectorResult result) { 39 PrintWriter pw = new PrintWriter( ps); 40 displayHTMLResultSet( pw, result); 41 pw.flush(); 42 } 43 44 public static void displayHTMLResultSet( PrintWriter pw, SQLVectorResult result) { 45 if( result == null || result.rows == null || result.columnName == null) 46 pw.println( "Internal error"); 47 pw.println( "<table border=\"2\" cellspacing=\"3\" cellpadding=\"5\">"); 48 pw.println( "<tr>"); 49 for( int i = 0; i < result.columnName.length; i++) 50 pw.print( "<th>" + result.columnName[i] + "</th>"); 51 pw.println( "</tr>"); 52 for( int i = 0; i < result.rows.size(); i++) { 53 Object[] row = (Object[])result.rows.elementAt( i); 54 pw.println( "<tr>"); 55 for( int j = 0; j < row.length; j++) { 56 pw.print( "<td>"); 57 if( row[j] == null) 58 pw.print( "NulL\t"); 59 else 60 pw.print( row[j].toString() + "\t"); 61 pw.println( "</td>"); 62 } 63 pw.println( "</tr>"); 64 } 65 pw.println( "</table>"); 66 } 67 }

This page was automatically generated by Maven