简体   繁体   English

无法通过Eclipse从Tomcat服务器重新连接到Derby

[英]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. 我在Win 7上运行,使用Eclipse 4.2在Tomcat 7服务器上启动Web应用程序并使用Derby数据库。 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. 如果我停止Eclipse并重新启动Eclipse,则可以解决问题,并且下次运行可以再次正常运行。

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. 在进行了一些调查之后,似乎出现问题是Derby端口(1527)没有从服务器的一次执行释放到另一次执行。 That seems very strange to me since Derby is started by the Tomcat instance which is a separate javaw process. 这对我来说很奇怪,因为Derby是由Tomcat实例启动的,而Tomcat实例是一个单独的javaw进程。

I've tried: 我试过了:

  • Configuring the Derby connection as a Tomcat resource 将Derby连接配置为Tomcat资源
  • Establishing the connection within my code (rather than via Tomcat resource) 在我的代码中建立连接(而不是通过Tomcat资源)
  • Both the embedded and the network driver 嵌入式和网络驱动程序
  • Starting / stopping the network driver from a servlet on startup and shutdown of the Tomcat server 在Tomcat服务器启动和关闭时从Servlet启动/停止网络驱动程序
  • Shutting down the embedded driver via servlet on shutdown of Tomcat 在Tomcat关闭时通过servlet关闭嵌入式驱动程序

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. 另一个似乎不相关的症状(除了作为关闭是否正确完成的可能指示)以外,我的数据库的db.lck文件从未删除。 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 . 经过进一步调查后,我将其称为: 无法为连接URL'null'创建类''的JDBC驱动程序:我不理解此异常 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. 这不是完全相同的事情,但是该解决方案(创建META-INF / context.xml)使它能够继续失败的呼叫而不是挂起,这是一个重大改进,表明它在很大程度上与之相关。

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). 事实证明,我在Tomcat的lib文件夹(对于Tomcat) 我的Eclipse中的应用程序的部署程序集中(而不是仅在构建路径中)有derby jars。 So Tomcat was using the built-in libs, while my app was using the embedded libs, and this resulted in conflicts. 因此,Tomcat使用内置库,而我的应用程序使用嵌入式库,这导致了冲突。 Leaving the libs as part of Tomcat and removing them from my war file solved the problem completely. 将这些库保留为Tomcat的一部分并从我的war文件中删除它们可以完全解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM