[ Team LiB ] Previous Section Next Section

18.6 Exercises

Exercise 18-1. Before you begin using JDBC, you must first have a database server and a JDBC driver for it, and you must know how to administer the server in order to do such things as create new databases. If you are not already an experienced database programmer, learning to do all this is more difficult than actually programming with JDBC. For this first exercise, therefore, obtain and install a database server if you don't already have one. Obtain and install a JDBC driver for it. Read the documentation for both the server and the driver. Learn the basics of the SQL language, if you don't already know it, and make a note of what SQL subset or SQL extensions are supported by your server and JDBC driver.

Exercise 18-2. Example 18-1 is a general-purpose SQL interpreter program that displays database query results in a rudimentary text-based table format. Modify the program so that it outputs query results using HTML table syntax, resulting in output suitable for display in a web browser. Test your program by issuing queries against some existing database.

Exercise 18-3. Write a program to create a database table of all files and directories stored on your computer (or at least all files and directories beneath a specified directory). Each entry in the database table should include a filename, a size, a modification date, and a boolean value that indicates whether it is a file or a directory. Run this program to generate a database of files. Write a second program that allows a user to make useful queries against this database, such as "list all files larger than 1 megabyte that are older than 1 month," or "list all files with the extension .java that were modified today." Optionally, design and create a GUI that allows a user to issue this sort of complicated query without knowing SQL.

    [ Team LiB ] Previous Section Next Section