Technology and Everything…..

Grails + Oracle

Posted by Shibu on October 19, 2010

If you are wondering how to use Grails  (from windows) with Oracle,

  • Download Grails from Grails  website. I used version 1.3.5
  • Unzip to your local folder (c:\grails-1.3.5)
  • You have to detine environment variable  JAVA_HOME. Ponit JAVA_HOME to your JDK. I am using version 5.0
  • Include the bin directory of grails installation into your PATH variable. (set PATH=%PATH%;c:\grails-1.3.5\bin)
  • Test your installation. Open a comman prompt window and type grails. You should see like below

Welcome to Grails 1.3.5 – http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: C:\grails-1.3.5

No script name specified. Use ‘grails help’ for more info or ‘grails interactive’ to enter interactive mode

  • If you see any error message, fix them before proceeding to next step
  •  You can see following steps in Grails website
  • Create a new project using command, grails create-app my-project, from command prompt. You issue this comman from any custom directory you have created for this project
  • Configure Data Source. This is optional, but this where we have setup if we need to connect Oracle Database. Following example shows what I have done to connect to my Oracle Database. You need to modify the DataSource.groovy file like below.

             dataSource {
                    pooled = true
                    driverClassName = “oracle.jdbc.OracleDriver”
                    username = “<schema_name>”
                    password = “<schema_password>”
                  hibernate {
                       cache.use_second_level_cache = true
                       cache.use_query_cache = true
                       cache.provider_class = ‘net.sf.ehcache.hibernate.EhCacheProvider’
                 // environment specific settings
                   environments {
                  development {
                          dataSource {
                                       dbCreate = “create-drop” // one of ‘create’, ‘create-drop’,’update’
                                        url =”jdbc:oracle:thin:@<ServerName>:<Port>:<SID>”
                   test {
                           dataSource {
                                        dbCreate = “update”
                                         url = “jdbc:oracle:thin:@<ServerName>:<Port>:<SID>”
                     production {
                                     dataSource {
                                            dbCreate = “update”
                                            url =”jdbc:oracle:thin:@<ServerName>:<Port>:<SID>”

You have to use appropriate server names, ports and SID names

  • Now you have to copy ojdbc14.jar to the lib directory of your Grails Application. This Oracel jar file you can get from any Oracle installation. For example if you have install SQLDeveloper, JDeveloper or Orcel XE you should be able to find this jar file within the subdirectory.
  • Now create domain class using command  grails create-domain-class book
  • The above command should create Book.groovy. Edit the Book.groovy file and add your attributes. This should match with your table field names. I added like below as suggested in Grails site,
class Book {
    String title
    String author
  • Create controller, grails create-controller my.project.Book
  • Above command should create file BookController.groovy. Modify this controller file like below as suggested in the Grails website
class BookController {
     def scaffold = Book // Note the capital "B"




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: