1

I'm running on Win 7 using Eclipse 4.2 starting a web app on a Tomcat 7 server and using Derby database. I have tried many approaches but run consistently into a common problem:

  • Everything works just fine the first time I start up and run.
  • When I redeploy my application after a change, all database connections hang (any kind of restart).
  • If I stop Eclipse and restart Eclipse, that clears up the problem and the next run works fine again.

Having done some investigation, it appears that the problem is that the Derby port (1527) is not released from one execution of the server to the next. That seems very strange to me since Derby is started by the Tomcat instance which is a separate javaw process.

I've tried:

  • Configuring the Derby connection as a Tomcat resource
  • Establishing the connection within my code (rather than via Tomcat resource)
  • Both the embedded and the network driver
  • Starting / stopping the network driver from a servlet on startup and shutdown of the Tomcat server
  • Shutting down the embedded driver via servlet on shutdown of Tomcat

Again, every approach works fine to connect the first time.

One other symptom that doesn't appear to be related (except for as a possible indicator of whether or not shutdown completes correctly) is that the db.lck file for my database never gets deleted. However, whether or not it exists has no bearing on whether or not I can reconnect (only stopping/starting eclipse has an impact).

Any insight would be appreciated. Thanks!

user1676075
  • 3,056
  • 1
  • 19
  • 26
  • Your question is confusing: at one point you talk about "the Derby port (1527)", while later you talk about "the embedded driver" and "the db.lck file". It seems that you are trying lots of different things, which makes it hard to give you concrete advice. Derby connections almost never "hang". Rather, they give exceptions. So, exactly what exception are you getting in your program? Print ALL the details and add them to your question: http://wiki.apache.org/db-derby/UnwindExceptionChain – Bryan Pendleton Mar 16 '14 at 16:20
  • That's part of my problem - no exceptions. Yes, wandering, trying lots of things to identify the problem and get it working. I'm now wondering if the problem may not have been database (despite that it manifested itself when I tried to connect to the database). I set up a separate MySQL server so I'd have a connection to a separate database, and I'm experiencing some similar issues. More investigation is needed. – user1676075 Mar 16 '14 at 19:11
  • Even with a separate MySQL database, re-deploying the application from Tomcat results in hangs for anything other than simple page requests. So it's not related to Derby (although the hang does appear to occur when I make a call that uses the database; web requests that do not use the database work). Any suggestions would be appreciated. – user1676075 Mar 16 '14 at 19:34
  • I got it to return errors instead of hang. I did so by following instructions here: http://stackoverflow.com/questions/11516747/cannot-create-jdbc-driver-of-class-for-connect-url-null-i-do-not-underst. – user1676075 Mar 16 '14 at 19:52

2 Answers2

1

After some further investigation I'm going to call this a duplicate of: Cannot create JDBC driver of class ' ' for connect URL 'null' : I do not understand this exception. It's not quite the same thing, but that solution (creating META-INF/context.xml) allows it to proceed to failing calls rather than hangs, which is a significant improvement and suggests it's largely related.

Community
  • 1
  • 1
user1676075
  • 3,056
  • 1
  • 19
  • 26
0

I did finally figure this out. It turns out I had the derby jars in the Tomcat lib folder (for Tomcat) and in the deployment assembly for my application in Eclipse (rather than just in the build path). So Tomcat was using the built-in libs, while my app was using the embedded libs, and this resulted in conflicts. Leaving the libs as part of Tomcat and removing them from my war file solved the problem completely.

user1676075
  • 3,056
  • 1
  • 19
  • 26