Enter your email address to subscribe to this blog.

Recent Comments

Intro to Spring Security Core for Grails
Eric Pierce said: Thanks for these screencasts, Dan! You made it crazy simple to get up and running w/security core h... [More]

Removing duplicates from an array of objects
Arvind said: Great tip, can't thank you enough for this. [More]

Intro to Spring Security Core for Grails
Santosh said: Thanks much for putting up these screencasts. As the others here I'm a beginner and I've been having... [More]

Grails Spring Security Plugin - Logout postOnly setting
eriihine said: I still had some issues with this one. It seems that the href link is always generating a GET method... [More]

Intro to Spring Security Core for Grails
Dan Vega said: Just a heads up but I decided to write up a quick post on your question just in case it trips up any... [More]

Writing SQL in a Grails Application

I have been using Hibernate for a couple years now and I love it. Every now and then though there are certain times when you are going to have to write some raw SQL. Maybe there is some performance issue you are trying to solve or maybe there are some custom functions that you just can't access. Whatever the case may be there are times when you will need to write some plain old SQL. The question came up on the Grails mailing list so I thought I would share it here.

First import the Sql class. Next define a property called dataSource. Spring will auto wire this dependency for us by name and with that we are ready to go. After we create a new instance of the sql class we can call a method on it called rows that can take a SQL statement. In this simple example we are just doing a select of a name property and this query brings back 3 rows. If you were to dump the class name of the rows variable you will see that its nothing more than an ArrayList. We can use the each method to loop over our collection and make sure it worked correctly. Now in the real world you world probably stick this in a service and return the rows to a view but you get the idea.

Pretty simple right? One last thing is we want to make sure we close the connection via the docs recommendations.

Constructs an SQL instance using the given Connection. It is the caller's responsibility to close the Connection after the Sql instance has been used. Depending on which features you are using, you may be able to do this on the connection object directly but the preferred approach is to call the close() method which will close the connection but also free any caches resources.


Typing practice for programmers

Google comes with the coolest services. This one allows programmers to practice typing. It allows you to pick a language and then test your speed as well as your efficiency. Head over to and test your skills right now.


Google Plus on my Android Tablet

Ever since I got my new shiny Samsung Galaxy 10.1 tablet about 6 months ago I have found myself using Google Plus more often. Recently there was an update and it was a good one. I love browsing Google plus more on my tablet than I do on the desktop. Here are a couple screen shots from my tablet. The first 2 are in landscape view and the second 2 are in portrait.


Google Doodles - How to view the entire archive

I love checking out the Google Doodles. These are the awesome graphics they come up with to replace the logo on special occasions. Today when I logged on there was a nice doodle in honor of the Olympics starting today.

Wouldn't it be great if you can see all of the past doodles? This morning I hit the "I'm Feeling Lucky" button without any search term an accident and I was taken to the mother ship. By default you will see a listing of all this doodles this year but you can switch between years. You can also filter by country, learn more about doodles and even buy some prints from their store. So you can take the path that I did to get there or you can just click on the image/link below.


Chrome Developer Tools: Tips & Tricks from Paul Irish

I found this video the other day and thought I would share it with you guys. In this video Paul walks through 12 tricks to becoming a quicker developer. If you use Chrome and find yourself living in the developer tools this is a must watch. If you already know about all 12 of these then you are ahead of the game but I am guessing you will learn at least 1 new thing from this video so enjoy.!


More Entries