开发者

Problem with dbUnit: java.sql.SQLException: Closed Statement

开发者 https://www.devze.com 2022-12-09 15:43 出处:网络
I have a strange problem with dbUnit. I use dbUnit 2.4.4, java 1.6, Spring (as db connection pool), Oracle 9 for my project with about 50 unit tests.

I have a strange problem with dbUnit. I use dbUnit 2.4.4, java 1.6, Spring (as db connection pool), Oracle 9 for my project with about 50 unit tests. For some of them (when I run whole set of tests) I get such exception:

Closed Statement
[junit] junit.framework.AssertionFailedError: Closed Statement
[junit]     at com.mypro开发者_StackOverflow中文版j.DataAccess.Internal.BaseDAOTest.importToDb(Unknown Source)
[junit]     at com.myproj.DataAccess.Internal.MyDAOTest.testGetBuyClientOrders(Unknown Source)
[junit]     at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[junit]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[junit]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)

importToDb method loads test data from XML file to database via dbUnit's DatabaseOperation.REFRESH.execute method and it is used in ALL tests. If I run these tests with problems separately, there is no problems for them. Do you have any ideas? Thanks!


I guess some of your tests close the database connection when they clean up. The next test tries to use this connection again for the import and fails.


When this happened to me, we had explicitly configured our connection cache to snipe long-lasting connections using two properties:

AbandonedConnectionTimeout
InactivityTimeout

See Oracle's docs here regarding timeout properties

It turned out that the query+processing time was just jumping the cusp of the two properties combined (AbandonedConnectionTimeout + InactivityTimeout < query time + resultset processing time).

To fix the issue, you can either raise your timeout limits or you can remove the timeout by setting them to 0 (the default)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号