Newer
Older
labs / tiddlers / content / labs / lab07 / _Labs_07_Complete the getSamples Method.md

The getSamples method is mostly complete --- it is just missing the SQL.

Refer to the class diagram again:

{{/Labs/07/Diagrams/Class Diagram}}

When we create a Sample object, we also need to create the associated Scientist object.

The SQL query for the getSamples method needs to return both the Sample and the associated Scientist.

  1. Add some data to the Sample and 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', 'lsmith@wet.co.nz', '+64 22 0191 1469');
    
     INSERT INTO Scientist (Scientist_Num, Surname, Other_Names, Email, Mobile_Phone) VALUES (12346, 'Towel', 'Terry', 'ttowel@wet.co.nz', '+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.');
  2. In DBeaver, create and test a query that returns all of the samples and their associated scientist.

  3. Once you have the query working, copy the SQL into the sql variable on line 53 of the SampleJdbcDAO class.

  4. 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.

  5. 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.

  6. You should now be able to view samples and record new samples.