Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
478
Chapter 18 JDBC and Database Connection Pooling
Listing 18.6 DatabaseUtilities.java (continued)
public static void printTable(Connection connection,
String tableName,
int entryWidth,
boolean close) {
String query = "SELECT * FROM " + tableName;
DBResults results =
getQueryResults(connection, query, close);
printTableData(tableName, results, entryWidth, true);
}
public static void printTableData(String tableName,
DBResults results,
int entryWidth,
boolean printMetaData) {
if (results == null) {
return;
}
if (printMetaData) {
System.out.println("Database: " +
results.getProductName());
System.out.println("Version: " +
results.getProductVersion());
System.out.println();
}
System.out.println(tableName + ":");
String underline =
padString("", tableName.length()+1, "=");
System.out.println(underline);
int columnCount = results.getColumnCount();
String separator =
makeSeparator(entryWidth, columnCount);
System.out.println(separator);
String row = makeRow(results.getColumnNames(), entryWidth);
System.out.println(row);
System.out.println(separator);
int rowCount = results.getRowCount();
for(int i=0; i
row = makeRow(results.getRow(i), entryWidth);
System.out.println(row);
}
System.out.println(separator);
}
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