Vaadin 8 on Grails 3
  • Introduction
  • Project setup
    • Environment setup
      • Unix based systems
      • Windows
    • Creating Project
      • Command line
      • IntelliJ IDEA
    • Plugin Configuration
      • UI class
      • URL mapping
      • Production mode
      • Async support
      • Themes
      • SASS compilation
      • Widgetset compilation
      • Servlet class
      • Spring component scan
      • UI provider
      • Open session in view
    • Clean up
    • Best Practices
  • Database
    • GORM
      • Create Domain Model
      • Transactions
      • LazyInitializationException
      • Open Session In View I.
      • Open Session In View II.
      • Table Container
    • Groovy SQL
      • Create Sql Bean
      • Execute SQLs
    • MyBatis
      • MyBatis Configuration
      • Reading Data with MyBatis
    • JdbcTemplate
      • Create JdbcTemplate Beans
      • Using JdbcTemplate
    • Clean Up When Using Alternatives
  • UI
Powered by GitBook
On this page

Was this helpful?

  1. Database
  2. Groovy SQL

Create Sql Bean

PreviousGroovy SQLNextExecute SQLs

Last updated 5 years ago

Was this helpful?

Example code is available on .

We can use class to access a database. The proper way to create new instance of Sql class is to define new bean in resources.groovy.

import groovy.sql.Sql

beans = {
    sql(Sql, ref('dataSource')) { bean ->
        bean.destroyMethod = 'close'
    }
}

If, from any reason, you would need to create Sql manually, you can the alternative approach to create Sql each time before SQL execution.

Sql sql = new Sql(dataSource: Grails.applicationContext.getBean('dataSource'))
// execute your queries
sql.close()
github.com/vaadin-on-grails/groovy-sql
Groovy Sql