File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Application Frameworks and the fly likes External sql with Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "External sql with Spring" Watch "External sql with Spring" New topic

External sql with Spring

Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

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 ( 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 ?

[ April 17, 2006: Message edited by: Satou kurinosuke ]

[My Blog]
All roads lead to JavaRanch
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
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é

Joined: Nov 24, 2005
Posts: 14688

Thank you Chris,
I'll have a look at iBatis in a little more depth then.
I agree. Here's the link:
subject: External sql with Spring
It's not a secret anymore!