I need some source code which does the following and so explains how it works:
>> The JApplet is used to read from and write into an external database.
The ResultSet contains the table rows with the following columns:"portfolioname", "stockname", "stock_ID", "purchase_Date", "numberOfStocks", "purchasePrice" .
This ResultSet needs to be shown in a JTable within the JApplet.
After it is displayed the user may select a row and change the data. The changed row needs to be stored/updated.
After this work is done it must be stored into the database.
1. The program should receive the data via JDBC from a database.
2. The ResultSet should be read in a 2-dimensional array: Object[ ][ ] dataModel;
The portfolioname and the stockname should be stored as Strings, the stock_ID as an Integer, the purchasePrice as a Float and the purchaseDate as a Date!
3. The classes Portfolio and Stock needs to exist:
public class Stock
private String name;
private Integer id;
private Float purchasePrice;
private Date purchaseDate;
}//end class Stock
public class Portfolio
private Vector allStocks;
private String name;
}//end class Portfolio
From the 2-dimensional array a new Portfolio instance must be created when the portfolioname occures the first time. Then the Stock must be created and added to the Portfolio.
If the portfolioname in the next row is the same only the Stock must be created and then added to the Portfolio object.
4. In the TableModel should be a Vector collecting all the Portfolio instances/objects. These portfolio objects should be used to generate the view of the table.
5. After displaying the table with those portfolios and stocks on the screen the user may select a row and change the data. For instance, he may increase the numberOfStocks from 20 to 50,...
These changes must take effect in the 2-dimensional array!!!
6. The user may delete or add any stock entries to a given portfolio or delete/add any portfolio. If a portfolio will be deleted all the containing stocks need to be deleted, too. These changes must take effect in the 2-dimensional array!!!
7. The up-to-date 2-dimensional array must be stored back into the database => the database needs to be updated.
(I want to extend teh TableModel from AbstractTableModel,
and I think I need a SelectionModel.)
Further question: When using Portfolio- and Stock objects -> is the 2-dimensional array needed?