aspose file tools*
The moose likes Spring and the fly likes Spring 101: DB Table to return a Map of Code,Description. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring 101: DB Table to return a Map of Code,Description." Watch "Spring 101: DB Table to return a Map of Code,Description." New topic
Author

Spring 101: DB Table to return a Map of Code,Description.

H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 471
    
    4
1. Here is basic pseudo JDBC code

ResultSet rs= SELECT * FROM CodeDescription (Code, Description)
Loop thru RS
Map.put (rs,getInt(1), rs.getString(2);
return Map;

2. How I can achieve this with Spring?

1M Thanks.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

H Paul wrote:1. Here is basic pseudo JDBC code

ResultSet rs= SELECT * FROM CodeDescription (Code, Description)
Loop thru RS
Map.put (rs,getInt(1), rs.getString(2);
return Map;

2. How I can achieve this with Spring?

1M Thanks.


We need more information. Spring isn't a JDBC implementation, so what do you want to use? Jdbc and with Spring's JdbcTemplate? Hibernate? Hibernate's implementation of JPA?

With JdbcTemplate there is a queryForMap method, where if you write your sql as a crosstab query, you can make the first column values be the column names and the description the values where you just pass the SQL string to the queryForMap method.

But which data access technology you are using tells us a good deal of what you should do.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 471
    
    4


1. (Sorry, if my intention is not clear. Thanks for the pointers)

2. I got what I wanted as shown above code. Just simple JDBC Template is enough.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

H Paul wrote:

1. (Sorry, if my intention is not clear. Thanks for the pointers)

2. I got what I wanted as shown above code. Just simple JDBC Template is enough.


Yep, that will work perfectly.

The approach that I was talking about would make it the query responsible for setting things up. But writing a crosstab query. But thinking about it, I am not sure you can write a crosstab query for that. But if you did then you can run

Map values = jdbcTemplate.queryForMap(crossTabQueryString);

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring 101: DB Table to return a Map of Code,Description.