Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
18.4 Applying the Database Utilities
485
Listing 18.11 EmployeeTest2.java
package coreservlets;
import java.sql.*;
/** Connect to Oracle or Sybase and print "employees" table
* as an HTML table.
*/
public class EmployeeTest2 {
public static void main(String[] args) {
if (args.length < 5) {
printUsage();
return;
}
String vendorName = args[4];
int vendor = DriverUtilities.getVendor(vendorName);
if (vendor == DriverUtilities.UNKNOWN) {
printUsage();
return;
}
String driver = DriverUtilities.getDriver(vendor);
String host = args[0];
String dbName = args[1];
String url =
DriverUtilities.makeURL(host, dbName, vendor);
String username = args[2];
String password = args[3];
String query = "SELECT * FROM employees";
DBResults results =
DatabaseUtilities.getQueryResults(driver, url,
username, password,
query, true);
System.out.println(results.toHTMLTable("CYAN"));
}
private static void printUsage() {
System.out.println("Usage: EmployeeTest2 host dbName " +
"username password oracle|sybase.");
}
}
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