This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Testing and the fly likes JUnit & JDBC problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "JUnit & JDBC problem" Watch "JUnit & JDBC problem" New topic

JUnit & JDBC problem

Paul Ramsden

Joined: Sep 22, 2000
Posts: 28
I am trying to test some classes which use JDBC connections. The first TestCase to run is able to get a connection for each test it runs, but all later TestCases exit with 'SQLException - No suitable driver'. The tests are being run in batch mode using ANT.
I guess it has something to do with class loading. Perhaps a new class loader for each test?
My test code run in 2 successive Junit tests
reproduces the problem.

Does anyone have any ideas?
[ July 15, 2003: Message edited by: Paul Ramsden ]
Paul Ramsden

Joined: Sep 22, 2000
Posts: 28
I have found a way around the problem.
I added fork="yes" to the junit task in ANT.
In spite of that, I would be glad to hear from anyone with insight into class loading in Junit.
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
Which test runner are you using? I know people often have problems with the GUI version...
Paul Ramsden

Joined: Sep 22, 2000
Posts: 28
ANT is running in text mode, the JUnit task is too.
Barry Hawkins

Joined: Jan 13, 2004
Posts: 8
I, too, am experiencing this problem, and setting fork="yes" in my <junit> task is what resolved the issue. I also happen to be using the IBM DB2 Connect JDBC Type 2 driver like you are in the code above. As you know, Type 2 drivers interface heavily with native code on the client. You may find that the "net" driver for DB2 (Type 4, IIRC) works without the fork setting on the <junit> task, as it does not interface with native code libraries. The issue appears to be related to Apache Bug Report #19275: <junit> fails when test classes load native code. Hope this helps some other folks.

Barry Hawkins<br />All Things Computed<br />site: <a href="" target="_blank" rel="nofollow"><br />weblog: [URL=]</a>
It is sorta covered in the JavaRanch Style Guide.
subject: JUnit & JDBC problem
It's not a secret anymore!