Skip to content

Lab 4-1-2: JDBC Part 2 - Insert

Objective

Write a class to insert a new employee into the Employees table.

Tip

  1. Use the command $ ant build_jdbc_lab to compile and build the class.
  2. Use the script $ ./runInsertLab.sh _first_name, last_name, ssn, dept, room, phone_ to run the class. You will need to create the script for this lab.
  3. The parameters first_name, last_name, ssn, dept, room, phone are placeholders for what you want to insert into the database.

Instructions

  1. Review the JDBC Learning Resources, such as:
  2. Create a new class, JDBCInsertEmployee.java.
  3. Using the JDBCSelectEmployees class from the JDBC Set Up lab as a model, write a class that inserts an employee into the Employees table.
  4. Refactor the large method into smaller single-purpose methods.
  5. The class should allow the user to input first name, last name, ssn, dept, room and phone at the command line.
  6. Create a new script, runInsertLab.sh, to run JDBCInsertEmployee. Use runJDBClab.sh and runAnalyzer.sh as models. Remember: the script will need to accept parameters for the employee values: first name, last name, ssn, dept, room, and phone.
  7. Once that is working, add code to read the newly added record from the database and display the record to the user.

Bonus

  1. Try using try-with-resources!

Screenshots

To receive credit for this lab save a screenshot in the projects/screenshots/week12 directory.

You may combine the below into one screenshot and name it lab1-2.png.

  1. lab1-insert-script.png: The command line output showing the results from running the runInsertLab.sh script.
  2. lab1-insert-success.png: The database showing that the new record was inserted.

Add, commit, and push and verify all work, including screenshots are visible in GitHub.


Rubric

All of the following must be satisfied to achieve a "Met" status

  • Screenshot clearly shows the results from executing runInsertLab.sh.
  • Screenshot clearly shows the record was added into the database.
  • Code and screenshots are properly named and saved in the correct directory.
  • All lab steps have been accurately and appropriately implemented.
  • Code adheres to the course coding standards.
  • Commit messages are concise, atomic, and effectively describe the change(s) made.
  • JavaDoc documentation is properly implemented, providing clarity and understanding of the code's functionality and usage.
  • External sources (websites, classmates, AI tools, etc), if utilized, are referenced and documented within the code as comments.

Additional Considerations

  • Correct implementation of try-with-resources to manage resources.
  • Large method have been refactored into smaller single-purpose methods.