Thursday, March 15, 2007

Grails : calling a stored procedure

My experience with grails is getting richer the longer I use it for web application developing. It's very nice that grails is built on top of spring framework which we can take advantage of. I am not a spring user before but with a help from the nice people at the grails forum I was able to achieve what I want to do.

Calling a stored procedure from a MySQL database or any other database is simple. First we need a datasource which spring could provide for us. I have the following code place in the resources.xml found in the spring folder in your grails folder.


<bean id="dataSource" class=" org.apache.commons.dbcp.BasicDataSource ">
<property name="driverClassName">
<value&rt;org.hsqldb.jdbcDriver</value>
</property>
<property name="url">
<value&rt;jdbc:hsqldb:hsql://localhost</value>
</property>
<property name="username">
<value&rt;sa</value>
</property>
<property name="password">
<value&rt;</value>
</property>
</bean>



I use connection pooling for better performance. In my controller here is how I use the datasource to call a store procedure.


class MainController {

def dataSource // using the datasource we define in the spring's resources.xml

def index = {
Sql sql = new Sql(dataSource)
def row = sql.execute("call create_daily_hours(${new Date()+1})")
}
}


That's it! Notice that I am using Groovy SQL instead of Spring JDBCTemplate. It's a lot more friendlier for a beginner.

Grails really makes everything easy here and provides a lot of flexibility thanks to it's nice integration with spring. From here everything is possible.


228 comments:

«Oldest   ‹Older   201 – 228 of 228
Anonymous said...

Thanks for sharing your thoughts about lose money. Regards

my webpage; how to make money working online

Anonymous said...

No subϳect if the Secгet ωriting is
liquid the glоbe сгop the cybеrspacе for jobs,
gaіning informatiοn and Merely for fun.
The obϳеctive of the game is to use
your рieceѕ your tidԁler сan takе ρart in οn a cуbeг
pet adoptіon ωebsіte.

Anonymous said...

Definitely imagine that that you stated. Your favorite justification appeared to be on the
net the easiest thing to remember of. I say to you,
I definitely get annoyed whilst other people consider concerns that they just don't realize about. You controlled to hit the nail upon the top and defined out the entire thing without having side-effects , other people can take a signal. Will likely be again to get more. Thank you

Also visit my web page :: how to make money on the internet fast

Anonymous said...

What i do not realize is actually how you're now not really much more neatly-appreciated than you may be now. You're so intelligent.
You realize thus significantly when it comes to
this matter, made me individually believe it from so many numerous angles.
Its like women and men are not fascinated until it's one thing to do with Woman gaga! Your own stuffs great. All the time maintain it up!

Also visit my homepage: ways To make money

Anonymous said...

You have made some really good points there.

I looked on the internet for more information about the issue and found
most individuals will go along with your views on this website.


my site make extra money online

Anonymous said...

Thanks for sharing your thoughts. I truly appreciate your efforts and I am
waiting for your further post thanks once again.



Feel free to surf to my homepage: ways of making money online

Anonymous said...

Hi, I read your blogs on a regular basis. Your writing
style is awesome, keep it up!

Also visit my weblog ... Best ways to make money online from home

Anonymous said...

You have made some decent points there. I checked on the web
to learn more about the issue and found most people will
go along with your views on this web site.

Also visit my web-site how to make easy money online

Anonymous said...

This article presents clear idea in support of the new visitors of
blogging, that genuinely how to do running a blog.

Here is my web page :: hot jobs in colorado

Anonymous said...

Undeniably believe that which you stated. Your favorite
justification appeared to be on the internet the easiest thing to be
aware of. I say to you, I definitely get annoyed while people think about worries that they just do not know
about. You managed to hit the nail upon the top and also defined
out the whole thing without having side effect , people could take a signal.
Will likely be back to get more. Thanks

Here is my page :: cedar finance

Anonymous said...

Normally I do not read post on blogs, however I would like to say that this write-up very pressured
me to check out and do it! Your writing taste has been surprised me.
Thanks, very great post.

Here is my site: http://www.youtube.com/watch?v=FZOuC8FraM0

Anonymous said...

I like the valuable info you provide in your articles.
I will bookmark your blog and check again here frequently.
I'm quite certain I will learn a lot of new stuff right here! Good luck for the next!

Visit my web blog: http://www.youtube.com/watch?v=caSEY6ykNKw

Anonymous said...

Great delivery. Solid arguments. Keep up the good work.


Feel free to visit my website :: make money fast online

Anonymous said...

Excellent weblog here! Also your website rather a lot up fast!
What web host are you using? Can I am getting your associate hyperlink on your host?
I desire my web site loaded up as quickly as yours lol

Review my website :: Make Money online from home

Anonymous said...

Υou can search listeԁ, unliѕted, lanԁlіne, &#1072n&#1281 entеrtain youгself ωith уour cell phone.


my webpage flupcommunity.de

Anonymous said...

Incredible story therе. What ocсurгed after?

Take care!

Feel free tο surf to my site may tinh

Anonymous said...

When I originally left a comment I appear to
have clicked on the -Notify me when new comments are added- checkbox and now every time a comment is added
I recieve 4 emails with the exact same comment.
Is there an easy method you can remove me from that service?
Many thanks!

Stop by my page ... free make money from home

Anonymous said...

Great blog you've got here.. It's hard to find high-quality writing
like yours these days. I seriously appreciate individuals like you!
Take care!!

Feel free to surf to my weblog http://www.youtube.com/watch?v=fCkK9-pzu_o

Anonymous said...

It's really a nice and useful piece of information. I am satisfied that you just shared this useful info with us. Please keep us informed like this. Thank you for sharing.

My site :: how to make extra money fast

Anonymous said...

Wow, marvelous blog layout! How long have you been blogging
for? you make blogging look easy. The overall look of your web site
is wonderful, let alone the content!

my blog - http://www.youtube.com/watch?v=gtCm82Itxoc

Anonymous said...

Just want to say your article is as amazing. The clarity in your post is simply nice and i can assume you are
an expert on this subject. Fine with your permission let me
to grab your RSS feed to keep updated with forthcoming post.
Thanks a million and please continue the gratifying work.

my webpage ... http://www.youtube.com/watch?v=jLuC1nG5cPk

Anonymous said...

http://www.dolabuy.com/celine-bags.htm celine bags rector desegregate dry hermes enamel bracelets sizes black louis vuitton iphone 4 case vinegar monogram speedy 25 interact louis vuitton job louis vuitton handbags 2012 uk celine handbags 2013

Anonymous said...

This is thе Sprint νersіοn, the Samѕung S Ρen.
Aftег that thеy'll be able to handle the following formats: MPEG4, H. 5 MP, from the chunky volume rocker and the micro USB charging and data cable connector on the bottom of the unit, and theWacomS-Pen slot is in the lower right hand corner. Pogue writes, \" With the Samsung galaxy Tab, click here.

Anonymous said...

I used to be able to find good info from your blog posts.



Here is my site :: Pirater Un Compte Facebook

Anonymous said...

I blog often and I seriously appreciate your content.

Your article has really peaked my interest.
I will book mark your blog and keep checking for new details about once a week.

I opted in for your Feed too.

Look into my homepage - binary forex options

Anonymous said...

Differences іn touchscrеen disрlаysThe
blaсkberry S3 Μini herе fаlls ѕomеwherein the miԁdle.
Ιn bгief, thе neω 10. Anу futuгe releаsе οf the blacκbeггy familу.
8 іnchеѕ diagonally ωhile Droid Razг Maxx ΗD sеe article.
Bоοѕt Μobilе is knoωn for рrοԁucing light weight ѕmartphoneѕ in thе Januаry-March quarter, compared wіth the design and
ԁisplay arena οf thе bаttle. Customers can mаκе theiг phones pеrfеct fог
videο chаttіng.

Αlѕo visit my blοg; blackberгy [http://www.wikung.dk]

Anonymous said...

Definitely believe that that you said. Your favorite justification appeared to be on the web the easiest thing to take into accout of.
I say to you, I certainly get annoyed even as folks consider concerns that
they just don't recognize about. You controlled to hit the nail upon the highest and also outlined out the entire thing with no need side-effects , people can take a signal. Will likely be back to get more. Thank you

Also visit my web blog; cedar finance when you lose ()

Zemkarlos said...

I appreciate you for giving such an informative portal. I find your site very informative and interesting and I like it! Thank you very much. workstations ft lauderdale

«Oldest ‹Older   201 – 228 of 228   Newer› Newest»