> For the complete documentation index, see [llms.txt](https://ondrej-kvasnovsky-2.gitbook.io/vaadin-on-grails/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ondrej-kvasnovsky-2.gitbook.io/vaadin-on-grails/database/groovy_sql/create_sql.md).

# Create Sql

> Example code is available on [github.com/vaadin-on-grails/groovy-sql](https://github.com/vaadin-on-grails/groovy-sql).

We can use [Groovy Sql](http://groovy.codehaus.org/api/groovy/sql/Sql.html) class to access a database. The proper way to create new instance of `Sql` class is to define new bean in `resources.groovy`.

```java
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.

```java
Sql sql = new Sql(dataSource: Grails.applicationContext.getBean('dataSource'))
// execute your queries
sql.close()
```
