Unable to reconnect to Derby from Tomcat server started via Eclipse

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!


    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.


    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.

    链接地址: http://www.djcxy.com/p/41242.html

    上一篇: Derby Network Server配置

    下一篇: 无法从通过Eclipse启动的Tomcat服务器重新连接到Derby