getSamples method is mostly complete --- it is just missing the SQL.
Refer to the class diagram again:
When we create a
Sample object, we also need to create the associated
The SQL query for the
getSamples method needs to return both the
Sample and the associated
Add some data to the
Scientist table so that you can test the query that you are about to create. Run the following
insert statements in DBeaver:
INSERT INTO Scientist (Scientist_Num, Surname, Other_Names, Email, Mobile_Phone) VALUES (12345, 'Smith', 'Jane', 'firstname.lastname@example.org', '+64 22 0191 1469'); INSERT INTO Scientist (Scientist_Num, Surname, Other_Names, Email, Mobile_Phone) VALUES (12346, 'Towel', 'Terry', 'email@example.com', '+64 21 2561 4789'); INSERT INTO Sample (Site_ID, Recorded_Date, Recorded_Time, Scientist_Num, Comments) VALUES('DN1', '2022-08-30', '10:57:40', 12345, 'Recent heavy rain. Water discoloured. Faint smell of effluent - possible sewer overflow upstream.'); INSERT INTO Sample (Site_ID, Recorded_Date, Recorded_Time, Scientist_Num, Comments) VALUES('DN5', '2022-08-31', '13:19:21', 12346, 'Nitrogen reading higher than expected.');
In DBeaver, create and test a query that returns all of the samples and their associated scientist.
Once you have the query working, copy the SQL into the
sql variable on line 53 of the
Examine the rest of the
getSamples method. Note that both a
Scientist object and a
Sample object are being created, with the
Scientist being passed to the
Sample object's constructor.
Test the system again. You will need to stop the project first using <Stop Build/Run">> and then run it again using the <> run project button.
You should now be able to view samples and record new samples.