I have three database tables defined below, column names mentioned in parenthesis:
Product (ProductID, Price, Last_Updated)
User (UserID, Name, Address, LocationID, Last_Updated)
Location (LocationID, Loc_Name, Last_Updated)
I want to use Java (JDK 1.5) to add all the column names of all the tables in one collection like a HashMap.
My problem is when a duplicate key is entered, the previous value is over ridden.
I am adding them like:
Map<String, String> map = new HashMap<String, String>();
map.add("ProductID", "Save the Product ID");
// ...
map.add("Last_Updated", "Save Last_Updated of Product table");
// ...
map.add("LocationID", "Save the LocationID");
// ...
map.add("Last_Updated", "Save Last_Updated of User table.");
Now the key Last_Updated is overridden with new value Save Last_Updated of User table.
But I want both the values.
Is there any way to implement this without using multiple HashMap structures?
Add the table names as a prefix to your column names. Then you can separate “Product.Last_Updated”, “User.Last_Updated” and “Location.Last_Updated”.
Obviously you have to use a separator char that is not used in the names of your tables or columns; a ‘.’ should do.