• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

External sql with Spring

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to know what is the best practice to write the sql code with Spring.
I don't want to write "select this from that" in my java classes.
I was thinking of :

1. Using a property file (sql.properties) to write all the necessary sql code
-> sql.sqlCountTrades=select count(*) from mytradetable
2. Use a PropertyPlaceholderConfigurer to read the property file
3. Set the sql properties of a dao bean, using values from the property file
-> <property name="sqlCountTrades"><value>${sql.sqlCountTrades}</value></property>

This works, but it is very painful to write.
Is there a good method to write all the sql out of the java code ?

This sounds like iBatis Map files, but is there a way to do it without iBatis ?

Thanks
[ April 17, 2006: Message edited by: Satou kurinosuke ]
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If externalizing sql is a big concern for you I would definitely recommend going with IBatis as you persistence solution. However, it would be very easy to just wire another attribute of your DAOs with the actual sql being fed from your spring config file.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Chris,
I'll have a look at iBatis in a little more depth then.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic