Lab 4-1-2: JDBC Part 2 - Insert
Objective
Write a class to insert a new employee into the Employees table.
Tip
- Use the command
$ ant build_jdbc_lab
to compile and build the class. - 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. - The parameters first_name, last_name, ssn, dept, room, phone are placeholders for what you want to insert into the database.
Instructions
- Review the JDBC Learning Resources, such as:
- Create a new class,
JDBCInsertEmployee.java
. - Using the
JDBCSelectEmployees
class from the JDBC Set Up lab as a model, write a class that inserts an employee into the Employees table. - Refactor the large method into smaller single-purpose methods.
- The class should allow the user to input first name, last name, ssn, dept, room and phone at the command line.
- Create a new script,
runInsertLab.sh
, to run JDBCInsertEmployee. UserunJDBClab.sh
andrunAnalyzer.sh
as models. Remember: the script will need to accept parameters for the employee values: first name, last name, ssn, dept, room, and phone. - Once that is working, add code to read the newly added record from the database and display the record to the user.
Bonus
- 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
.
lab1-insert-script.png
: The command line output showing the results from running therunInsertLab.sh
script.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.