Skip to content

Lab 4-1-3 - JDBC Lab Part 3 - Prepared Statements

Objective

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

Database commands

Start MariaDB service: sudo service mariadb start
Login as student: mariadb -ustudent -p
Password: student

Build and Run the Lab

  1. Use the command $ ant build_jdbc_lab to compile and build the class.
  2. Use the script $ ./runPreparedStatement.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 learning resources about Prepared Statements.

  2. Create a new class, JDBCPreparedStatement.java.

  3. Using the class from the previous lab as a starting point, use the PrepareStatement class to insert a new employee.

  4. Create a new script, runPreparedStatement.sh, to run JDBCPreparedStatement. 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.


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-3.png.

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

Submit Weekly Labs

  1. Add, commit, and push!
  2. Verify all work, including screenshots are visible in GitHub.
  3. Select 00 Weekly Labs Ready for Review.
  4. Enter the title: Week 12 Labs
  5. Answer the reflection questions in the space provided.
  6. Click Create.

Rubric

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

  • Screenshot clearly shows the results from executing runPreparedStatement.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

  • Issue created correctly with thoughtful answers to the reflection questions.
  • Large method have been refactored into smaller single-purpose methods.