1

我在 Grails 服务中运行一些 Groovy SQL 并经常收到以下错误消息:

org.springframework.transaction.interceptor.TransactionInterceptor - 应用程序异常被提交异常 java.sql.SQLException 覆盖:连接已关闭。

据我所知,JDBC 连接池被配置为经常删除未使用的连接(并在每次使用连接时重置放弃的计时器)。我认为这是我的麻烦的根本原因 - 连接被池关闭,但我的代码不知道这一点。我想知道是否有办法从代码中而不是通过更改连接池配置来处理这个问题。

我的代码是这样的(请原谅sql2变量名)......

def sql = new Sql(dataSource)
sql.firstRow ...
sql.close()

// long running non-db code (an api call)

def sql2 = new Sql(dataSource)
sql2.executeUpdate ... // THIS IS WHERE THE ERROR HAPPENS
sql2.close

我的想法是这new Sql(dataSource)会给我一个新的联系,但看起来我错了。有没有办法获得新的连接,或者以其他方式处理这个问题?

池配置:

maxIdle="0"
maxWait="30000"
removeAbandoned="true"
testOnBorrow="true"
validationInterval="34000"
validationQuery="select sysdate from dual"
removeAbandonedTimeout="60"
logAbandoned="true"
jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.StatementCache;org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer"
4

0 回答 0