retrieve data from database using Hashmap (multiple values in one key)
hi i want to retrieve all data from the specific field in database using hashmap.. unfortunately, only the last value was retrieve.. what will i do?
Re: retrieve data from database using Hashmap (multiple values in one key)
Fix the logic in your code.
Re: retrieve data from database using Hashmap (multiple values in one key)
You want to retrieve all data from a table in database, isn't it?
For example:
You have a table in database:
table: Names
id name
--------------------------
1 Adam
2 Brian
3 John
4 Michael
this code can retrieve all data from this table:
Code Java:
...
Map<Integer, String> names = new HashMap<Integer, String>();
...
Statement s = connection.createStatement();
ResultSet r = s.executeQuery("SELECT * FROM Names");
while(r.next()){
Integer id = new Integer(r.getInt("id"));
String name = new String(r.getString("name"));
names.put(id, name);
}
...
names collection will contain all ids and names from Names table.