18.2. Basic JDBC Example
Listing 18.3 presents a simple class called FruitTest that follows the seven steps outlined in the previous section to show a simple table called fruits. It uses the command-line arguments to determine the host, port, database name, and driver type to use, as shown in Listings 18.1 and 18.2. Rather than putting the driver name and the logic for generating an appropriately formatted database URL directly in this class, these two tasks are spun off to a separate class called DriverUtilities, shown in Listing 18.4. This separation minimizes the places that changes have to be made when different drivers are used.
This example does not depend on the way in which the database table was actually created, only on its resultant ...
Get Core Servlets and JavaServer Pages™ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.