Create a RESTful web service that stores phone book entries in the database Phon
ID: 668304 • Letter: C
Question
Create a RESTful web service that stores phone book entries in
the database PhoneBookDB and a web client application that consumes this service. The web service
should output XML. Use the steps in Section 30.2.1 to create the PhoneBook database and a data
source name for accessing it. The database contains one table—PhoneBook—with three columns—
LastName, FirstName and PhoneNumber. The LastName and FirstName columns store up to 30 characters.
The PhoneNumber column supports phone numbers of the form (800) 555-1212 that contain
14 characters. Use the PhoneBookDB.sql script provided in the examples folder to create the Phone-
Book table.
Give the client user the capability to enter a new contact (web method addEntry) and to find
contacts by last name (web method getEntries). Pass only Strings as arguments to the web service.
The getEntries web method should return an array of Strings that contains the matching
phone book entries. Each String in the array should consist of the last name, first name and phone
number for one phone book entry. These values should be separated by commas.
The SELECT query that will find a PhoneBook entry by last name should be:
SELECT LastName, FirstName, PhoneNumber
FROM PhoneBook
WHERE (LastName = LastName)
The INSERT statement that inserts a new entry into the PhoneBook database should be:
INSERT INTO PhoneBook (LastName, FirstName, PhoneNumber)
VALUES (LastName, FirstName, PhoneNumber)
Explanation / Answer
DROP TABLE PhoneBook; CREATE TABLE PhoneBook ( FirstName VARCHAR (50) NOT NULL, LastName VARCHAR (50) NOT NULL, PhoneNumber VARCHAR (50) NOT NULL ); INSERT INTO PhoneBook (FirstName,LastName,PhoneNumber) VALUES ('Bob', 'Green', '5555551111'), ('Sue', 'Black', '5555552222'), ('Liz', 'White', '5555553333'), ('Paul', 'Blue', '5555554444')