from database we retrieve data after that i want to put column name as key and row as value
so key are same for all row(like-select * from emp) means i want all data put in a map.
You need to first read table's metadata in order to obtain column names that you would use as a key for your map. As I understood your requirement, for the given key (column name) value would be list of strings (or whatever type) containing values stored in that column.
Though I have no idea why you would want to do something like that... Database contains structured data (or at least it should), and storing data in maps by column name doesn't sound so reasonable to me.
The quieter you are, the more you are able to hear.
Ritesh raushan
Ranch Hand
Joined: Aug 29, 2012
Posts: 99
posted
0
Kemal Sokolovic wrote:
Though I have no idea why you would want to do something like that... Database contains structured data (or at least it should), and storing data in maps by column name doesn't sound so reasonable to me.
actually this is from spring where List l=queryForList("select Query") is apredefined method which return List and internally convert each row in a map and he takes column name as a key and a row as a value after that he puts all map object in a ArrayList and arraylist return
Kemal Sokolovic wrote:Though I have no idea why you would want to do something like that... Database contains structured data (or at least it should), and storing data in maps by column name doesn't sound so reasonable to me.
Actually for some use cases it is the most reasonable and better way.
Let me give you an exact instance.
I had a Charting UI component to make a Pie chart. To determine the pie slices names and size the component wanted a Map, where the key is the pie slice name and the value was the size. Why go to the database, get a ResultSet, have to convert it to a Domain object to pass up to the UI layer, then write code to convert the domain object into a Map. Why not query for that Map at the DAO layer with one line of code, and just pass the Map up to the client.
Well, that was a good example, now I have an idea why something like that should be done. Thanks for clarification!
I guess I've lost the big picture because the original post didn't contain more details about possible applications of that approach (which is why I like OP to provide details like that), and I thought only of the basic case - read data from each column, and store it into Map to manipulate it outside the database. Hence, it didn't make sense to me because it would be difficult and more complex to keep database structure.
Edit: Little off topic, but I just saw that with this one I have published 0.5kPosts!
Kemal Sokolovic wrote:Well, that was a good example, now I have an idea why something like that should be done. Thanks for clarification!
I guess I've lost the big picture because the original post didn't contain more details about possible applications of that approach (which is why I like OP to provide details like that), and I thought only of the basic case - read data from each column, and store it into Map to manipulate it outside the database. Hence, it didn't make sense to me because it would be difficult and more complex to keep database structure.
Edit: Little off topic, but I just saw that with this one I have published 0.5kPosts!
Exactly, there are some, few use cases where it really does make sense. But most of the time it doesn't
Yes, there are some details missing from the original posters posts.