Add Persistent Data Storage To 641695

Add Persistent Data Storage To

CIS355A Week 6 Lab—Database OBJECTIVES · Add persistent data storage to your Week 5 Lab using the MySQL Database. PROBLEM: Stocks4U Portfolio Management System The portfolio management system you developed for Stocks4U needs the ability to save and restore a user’s data from a MySQL Database. FUNCTIONAL REQUIREMENTS · The functional requirements of the Stocks4U application have not changed, and the Graphical User Interface has not changed from Week 5. StockIO class Modify the StockIO class to read and write the stock information to and from a MySQL database. Called “StocksDB†This class should have two methods. · getData—reads data from file, returns data in array list of stock objects · saveData—writes data from an array list to the data base in proper format · deleteStock—deletes the identified stock from the database · updateStock—updates the identified stock in the database. The database connection string will be stored as a constant in the StockIO class. GUI class Note that you will need to add an ArrayList to your GUI class to manage the data to/from the file. It will act as a parallel array to your DefaultListModel. Any time you add a stock, you must add it in BOTH places. Any time you remove a stock, you must remove it in BOTH places. File—open should open the database, retrieve the existing records and display the existing records. File—save should save all records, new and old, back to the database. File—exit should exit the program. The total value of the portfolio should be displayed at all times and updated anytime a stock is added or removed. Sample GUI RUBRIC StockIO class · getData method reads from database · saveData method writes data to the database · udpateStock method updates the identified stock to the database · deleteStock method deletes the identified stock in the database 40 Code style 5 Lab Report 10 TOTAL 55 CODE STYLE REQUIREMENTS · Include meaningful comments throughout your code. · Use meaningful names for variables. · Code must be properly indented. · Include a comment header at beginning of each file, example below. / Program Name: ProgramName.java Programmer's Name: Student Name Program Description: Describe here what this program will do */ DELIVERABLES Submit as a SINGLE zip folder · all Java files; and · the Lab report. Follow assignment specification regarding class/method names. Note that your Java file name must match class name (DO NOT rename). CIS355A Week 5 Lab Instructions Page 2

Paper For Above instruction

Add Persistent Data Storage To

Enhancing Stocks4U Portfolio Management System with MySQL Data Storage

The core objective of this assignment is to augment the existing Stocks4U Portfolio Management System developed in Week 5 by integrating persistent data storage using a MySQL database. This enhancement ensures that users can save their stock portfolio data to a database and retrieve it efficiently, thereby improving data durability and accessibility. The system retains its original graphical user interface (GUI) and functional features, but now relies on MySQL for data storage rather than file-based persistence.

Introduction

In the original Stocks4U application, stock data was stored in local files, which posed limitations in data integrity, scalability, and ease of access. Moving to a MySQL database offers numerous advantages, including centralized data management, better concurrency control, and robust querying capabilities. The goal is to modify the system's data access layer, specifically the StockIO class, to interact with the database instead of files, adhering to best practices in database programming and code organization.

Key Functional Requirements

The existing application functionality remains unchanged: the GUI allows users to add, delete, and update stocks, with the total portfolio value displayed dynamically. The primary modification is to replace file-based data operations with database interactions. This involves implementing four main methods within the StockIO class:

  1. getData(): Reads stock data from the MySQL database and returns it as an ArrayList of Stock objects.
  2. saveData(): Writes all stock data from an ArrayList into the database, ensuring the database reflects the latest state of the portfolio.
  3. deleteStock(): Deletes the specified stock record from the database.
  4. updateStock(): Updates the information of a specific stock in the database.

The StockIO class will store the database connection string as a constant, following best practices for maintainability. The GUI class will maintain an ArrayList parallel to the DefaultListModel to manage stocks dynamically. Any addition or removal of stocks must be synchronized across both data structures to maintain consistency.

Implementation Details

Database Connectivity

To establish a connection with the MySQL database, the StockIO class will include a connection string constant, including credentials and database URL. JDBC (Java Database Connectivity) API will be used to execute SQL statements, manage connections, and handle exceptions properly.

Methods

  • getData(): Will execute a SELECT statement to retrieve all records from the stock table, instantiate Stock objects for each record, and return them in an ArrayList.
  • saveData(): Will clear existing records and insert the current set of stocks into the database. Alternatively, it can update existing records to match the ArrayList content.
  • deleteStock(): Executes a DELETE SQL command targeting a specific stock symbol or ID.
  • updateStock(): Executes an UPDATE SQL command to modify details of a specific stock record based on the provided Stock object.

GUI Updates

The GUI will load existing stocks from the database upon opening via the getData() method and display them. When users add or remove stocks, the corresponding methods in StockIO will be invoked to update the database, and the GUI's ArrayList and DefaultListModel will be updated to reflect changes. The total portfolio value will be recalculated and displayed each time the data changes.

Code Style and Documentation

All Java code must include meaningful comments, especially headers documenting class purpose, author, and date. Variable names should be descriptive to enhance code readability. Proper indentation should be maintained for clarity. Example comment header for each file:

/**

Program Name: ProgramName.java

Programmer's Name: Student Name

Program Description: Describe here what this program will do

*/

Deliverables

  • A single ZIP archive containing all Java source files used in the implementation.
  • The completed Lab report detailing the development process, design decisions, and testing outcomes.

Conclusion

By integrating MySQL database interactions into the Stocks4U system, this assignment enhances data persistence, integrity, and scalability. The approach encompasses modifying the data access layer, updating the GUI logic for synchronization, and ensuring robust code practices are followed throughout. This process exemplifies best practices in software development involving databases and GUI applications.

References

  • Oracle. (2020). JDBC basics. Oracle Documentation. https://docs.oracle.com/en/javase/8/docs/technotes/guides/jdbc/
  • MySQL. (2022). MySQL Connector/J Developer Guide. https://dev.mysql.com/doc/connector-j/en/
  • Gamma, E., Helm, R., Johnson, R., & Vlissides, J. (1994). Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley.
  • Fowler, M. (2004). Patterns of Enterprise Application Architecture. Addison-Wesley.
  • Elmasri, R., & Navathe, S. B. (2015). Fundamentals of Database Systems (7th ed.). Pearson.
  • Schlossnagle, G. (2008). Practical MySQL. Apress.
  • Rob, P., & Coronel, C. (2007). Database Systems: Design, Implementation, & Management. Cengage Learning.
  • Java SE Documentation. (2023). JDBC API. Oracle. https://docs.oracle.com/en/java/javase/11/docs/api/java.sql/module-summary.html
  • Baeldung. (2023). Introduction to JDBC. https://www.baeldung.com/java-jdbc
  • Liang, Y. D. (2013). Introduction to Java Programming and Data Structures. Pearson.