Java Reference
In-Depth Information
Q
UIZ
P
ROGRAMMING
E
XERCISES
*32.1
(
Access and update a
Staff
table
) Write a program that views, inserts, and
updates staff information stored in a database, as shown in Figure 32.27a. The
View
button displays a record with a specified ID. The
Insert
button inserts a new
record. The
Update
button updates the record for the specified ID. The
Staff
table is created as follows:
create table
Staff (
id
char
(
9
)
not null
,
lastName
varchar
(
15
),
firstName
varchar
(
15
),
mi
char
(
1
),
address
varchar
(
20
),
city
varchar
(
20
),
state
char
(
2
),
telephone
char
(
10
),
email
varchar
(
40
),
primary key
(id)
);
(a)
(b)
F
IGURE
32.27
(a) The program lets you view, insert, and update staff information. (b) The
PieChart
and
BarChart
components display the query data obtained from the data module.
**32.2
(
Visualize data
) Write a program that displays the number of students in each
department in a pie chart and a bar chart, as shown in Figure 32.27b. The number
of students for each department can be obtained from the
Student
table (see
Figure 32.4) using the following SQL statement:
select
deptId,
count
(*)
from
Student
where
deptId
is not null
group by
deptId;
*32.3
(
Connection dialog
) Develop a subclass of
BorderPane
named
DBConnectionPane
that enables the user to select or enter a JDBC driver and a URL and to enter a user-
name and password, as shown in Figure 32.28. When the
Connect to DB
button is
clicked, a
Connection
object for the database is stored in the
connection
prop-
erty. You can then use the
getConnection()
method to return the connection.
Search WWH ::
Custom Search