Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • 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
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!