Newer
Older
labs / tiddlers / content / labs / lab07 / _Labs_07_Complete the addScientist Method.md
  1. Open the ScientistJdbcDAO class in the dao package.

    DAO is short for Data Access Object and is one of the encapsulation techniques that programmers use to encapsulate the code that manages the storage and retrieval of data. You can read more about the DAO pattern (if you are interested) at:

    https://en.wikipedia.org/wiki/Data_access_object

    The ScientistJdbcDAO class uses JDBC to store and retreive scientists in the Scientist table in the database.

  2. Take a look at the addScientist method. This method is used to store a scientist object in the database.

    Read through the code for this method --- the comments explain what each line of code is doing.

    The SQL for the insert is declared in the sql variable. Note the ? characters --- these are placeholders for the values for the scientist.

  3. Before executing the query, we need to first provide values for these placeholders. The code that does this looks like:

    stmt.setString(1, aScientist.getSurname());

    This code is getting the surname out of the scientist object that was passed to the addScientist method and inserting it into the SQL statement in the first placeholder. The 1 refers to the position of the placeholder --- 1 is the first, 2 is the second, etc.

  4. The code is currently not handling the email or mobile phone number. Add code in the indicated locations for handling the email and mobile phone number.