2011-06-09 75 views
2

我使用安装在一个Tomcat 6的Apache Derby - 嵌入模式 - 无法启动数据库,同时重装一个servlet

不幸的是Servlet应用程序中的文件系统上的嵌入式Apache Derby数据库我已经在几乎没有任何控制tomcat配置和其他servlet安装,我无法使用德比的网络/服务器模式。

无论何时重新载入servlet(例如,出于调试目的),我都有一个小问题,即数据库似乎保持锁定或由旧线程/ servlet实例保留锁定状态,并且由Tomcat初始化。

我的应用程序试图打开/创建数据库,它工作正常,除非,如我所说,我重新加载servlet。这似乎是因为没有方法被调用,只要tomcat重新加载servlet,我没有时间从正确的线程关闭数据库连接,并且当我尝试在重新加载的实例上启动新连接时,我得到:

java.sql.SQLException: Failed to start database 'C:\mydb.db' with class loader WebappClassLoader 
context: /Myapp 
delegate: false 
repositories: 
/WEB-INF/classes/ 
----------> Parent Classloader: 
[email protected] 
, see the next exception for details. 
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source) 
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source) 
at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source) 
at org.apache.derby.impl.jdbc.EmbedConnection.bootDatabase(Unknown Source) 
at org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown Source) 
at org.apache.derby.impl.jdbc.EmbedConnection30.<init>(Unknown Source) 
at org.apache.derby.impl.jdbc.EmbedConnection40.<init>(Unknown Source) 
at org.apache.derby.jdbc.Driver40.getNewEmbedConnection(Unknown Source) 
at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source) 
at org.apache.derby.jdbc.AutoloadedDriver.connect(Unknown Source) 
at java.sql.DriverManager.getConnection(Unknown Source) 
at java.sql.DriverManager.getConnection(Unknown Source) 
at myapp.Myapp.init(Myapp.java:88) 
at javax.servlet.GenericServlet.init(GenericServlet.java:212) 
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173) 
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:809) 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129) 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) 
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) 
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) 
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) 
at java.lang.Thread.run(Unknown Source) 
Caused by: java.sql.SQLException: Failed to start database 'C:\mydb.db' with class loader WebappClassLoader 
context: /Myapp 
delegate: false 
repositories: 
/WEB-INF/classes/ 
----------> Parent Classloader: 
[email protected] 
, see the next exception for details. 
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) 
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source) 
... 31 more 
Caused by: java.sql.SQLException: Another instance of Derby may have already booted the database C:\mydb.db. 
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) 
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source) 
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source) 
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source) 
... 28 more 
Caused by: ERROR XSDB6: Another instance of Derby may have already booted the database C:\mydb.db. 
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) 
at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.privGetJBMSLockOnDB(Unknown Source) 
at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.run(Unknown Source) 
at java.security.AccessController.doPrivileged(Native Method) 
at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.getJBMSLockOnDB(Unknown Source) 
at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.boot(Unknown Source) 
at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source) 
at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source) 
at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(Unknown Source) 
at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Unknown Source) 
at org.apache.derby.impl.store.raw.RawStore.boot(Unknown Source) 
at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source) 
at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source) 
at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(Unknown Source) 
at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Unknown Source) 
at org.apache.derby.impl.store.access.RAMAccessManager.boot(Unknown Source) 
at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source) 
at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source) 
at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(Unknown Source) 
at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Unknown Source) 
at org.apache.derby.impl.db.BasicDatabase.bootStore(Unknown Source) 
at org.apache.derby.impl.db.BasicDatabase.boot(Unknown Source) 
at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source) 
at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source) 
at org.apache.derby.impl.services.monitor.BaseMonitor.bootService(Unknown Source) 
at org.apache.derby.impl.services.monitor.BaseMonitor.startProviderService(Unknown Source) 
at org.apache.derby.impl.services.monitor.BaseMonitor.findProviderAndStartService(Unknown Source) 
at org.apache.derby.impl.services.monitor.BaseMonitor.startPersistentService(Unknown Source) 
at org.apache.derby.iapi.services.monitor.Monitor.startPersistentService(Unknown Source) 
... 28 more 

我试图删除db.lck文件,然后尝试创建新的连接,但该文件被tomcat锁定,无法删除。 还通过使用DriverManager.getConnection(“jdbc:derby:; shutdown = true”);关闭所有derby系统。

导致正确的异常,但是当应用程序创建新连接时,存在多次访问相同的错误。

有什么办法可以避免这种情况?

+1

请不要删除db.lck文件!通过让两个Derby引擎同时访问数据库而无需协调,它可以帮助您避免损坏数据库。 – 2012-10-17 20:27:29

回答

0

我的建议是你需要修改context.xml文件的内容。

<Context> 
    <Resource name="jdbc/testDB" auth="Container" type="javax.sql.DataSource" 
      maxActive="20" maxIdle="10" username="classiccars" password="classiccars" 
      driverClassName="org.apache.derby.jdbc.EmbeddedDriver" 
      url="jdbc:derby:C:\Users\Nakshatra\.myeclipse\derby\myeclipse"/> 
</Context> 


    Note:you need to log on as an Administrator if you use Windows 7 OS. 
    http://www.mytechguide.org/106/how-to-log-on-as-administrator-in-windows-7/ 
0

在更改Tomcat 8.0的上下文路径后,我遇到了同样的问题。 真正帮助我 - Eclipse重新启动。