• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

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

 
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ranger
Posts: 17344
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
H Paul
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 17344
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!