Java Reference
In-Depth Information
Lab 18.1: Using JDBC
This lab is designed to help you become familiar with using JDBC.
1. Start by creating a database to store music CDs. Add a table named
CDs and columns for the artist and title.
2. Write a class to represent a music CD that does not contain any
database code, similar to the Movie class in this chapter.
3. Write a class named CDDatabase. Add a method to CDDatabase
called insertCD() that takes in a CD object and inserts it in the
database.
4. Add a method named removeCD() to CDDatabase that takes in a
CD object and removes it from the database.
5. Add a method named findByTitle() that takes in a String and returns
an array of CD objects. The array represents CDs in the database
whose title matches any part of the given string.
6. Add a method named findByArtist() that takes in an artist's name
and returns an array containing all CDs in the database that match
the given artist.
7. Save and compile the CDDatabase class.
8. Write a program named FillDatabase that fills the database with a
collection of CDs, or simply add CDs to the database manually
using your database program.
9. Write a program that tests all the methods of the CDDatabase, mak-
ing sure they work correctly.
When you invoke a method on the CDDatabase object, the results
should be consistent with the data in the database. For example, invoking
insertCD() should insert a row in the table, and invoking removeCD()
should remove a row from the table.
Lab 18.2: Using Result Sets
In this lab, you will create a GUI for the results in Lab 18.1 and then add
a feature that allows you to scroll through the CDs in the database.
Search WWH ::




Custom Search