aspose file tools
The moose likes Other Application Frameworks and the fly likes External sql with Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Other Application Frameworks
Reply Bookmark "External sql with Spring" Watch "External sql with Spring" New topic
Author

External sql with Spring

Christophe Verré
Marshal

Joined: Nov 24, 2005
Posts: 14361

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 ]

[SCBCD Wall of Fame] [My Blog]
All roads lead to JavaRanch
Help Japan. Make a donation.
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é
Marshal

Joined: Nov 24, 2005
Posts: 14361

Thank you Chris,
I'll have a look at iBatis in a little more depth then.
 
 
subject: External sql with Spring
 
Threads others viewed
Ibatis : java.lang.NoClassDefFoundError: com/ibatis/common/xml/NodeletException
P6spy does not create spy.log for stand-alone Java program
Metro-iBATIS Problem while deploying web service using iBatis as mapping techonlogy.
"Could not get a good connection to the database" when trying to access remote server
listing hibernate named queries from java
IntelliJ Java IDE