After running into this question today: Grails query not using GORM I wonder if using groovy.sql.Sql or JDBC comes with the benefits of connection pooling?
I can see under some circumstances how going GORMless could be beneficial, but lack of conn pooling would eliminate it as an option.
Would we also get the benefits of prepared statements?
One of the main uses of a
DataSourceis to provide connection pooling. If you have setpooled = trueinDataSource.groovythen the injected dataSource will give you a connection from the pool when you execute the query.Groovy SQL also provides querying using prepared statements:
You can also enable
PreparedStatementcaching on the Sql object for performance: