我正在使用以下代码中所示的现有DataSource创建全局groovy.sql.Sql
连接:
def checkConnection() {
if (sql == null || sql.getConnection() == null) {
sql = new Sql(dataSource)
}
}
在这里,我正在调用多种方法来使用此全局SQL连接从数据库获取不同的不同数据。
注意
当我不使用sql.cacheStatements = true
时,我的代码工作正常。但是,当我使用sql.cacheStatements = true
时,它每次都会关闭我的连接。
首先,对于每种方法,我都调用checkConnection()
方法。
def getCount() {
checkConnection()
sql.cacheStatements = true
rows = sql.rows("select count(columnName) from tableName where date>= someValue and age>= someValue")
return rows
}
问题: 如何使用groovy的groovy.sql.Sql
连接对语句使用缓存概念。