Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
18.3 Some JDBC Utilities
479
Listing 18.6 DatabaseUtilities.java (continued)
// A String of the form "| xxx | xxx | xxx |"
private static String makeRow(String[] entries,
int entryWidth) {
String row = "|";
for(int i=0; i
row = row + padString(entries[i], entryWidth, " ");
row = row + " |";
}
return(row);
}
// A String of the form "+ + + +"
private static String makeSeparator(int entryWidth,
int columnCount) {
String entry = padString("", entryWidth+1, " ");
String separator = "+";
for(int i=0; i
separator = separator + entry + "+";
}
return(separator);
}
private static String padString(String orig, int size,
String padChar) {
if (orig == null) {
orig = "";
}
// Use StringBuffer, not just repeated String concatenation
// to avoid creating too many temporary Strings.
StringBuffer buffer = new StringBuffer("");
int extraChars = size orig.length();
for(int i=0; i
buffer.append(padChar);
}
buffer.append(orig);
return(buffer.toString());
}
}
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved