【问题标题】:Apache Derby - Embedded Mode - Failed to start database while reloading a servletApache Derby - 嵌入式模式 - 重新加载 servlet 时无法启动数据库
【发布时间】:2023-03-11 12:25:01
【问题描述】:

我在 Tomcat 6 上安装的 servlet 应用程序中的文件系统上使用嵌入式 apache derby 数据库。

不幸的是,我几乎无法控制 tomcat 配置和其他 servlet 安装,并且我无法为 derby 使用网络/服务器模式。

每当重新加载 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:
org.apache.catalina.loader.StandardClassLoader@482923
, 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:
org.apache.catalina.loader.StandardClassLoader@482923
, 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 锁定,无法删除。 还使用以下方法关闭所有 derby 系统:DriverManager.getConnection("jdbc:derby:;shutdown=true");

导致正确的异常,但是当应用程序创建新连接时,同样出现多路访问的错误。

有什么办法可以避免吗?

【问题讨论】:

  • 请不要删除 db.lck 文件!它可以通过让 Derby 引擎的两个副本同时访问数据库而无需协调,从而避免损坏数据库。

标签: servlets derby


【解决方案1】:

我的建议是你需要修改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/

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2021-10-11
      • 2012-09-21
      • 2018-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-18
      相关资源
      最近更新 更多