3

这是最多的主题之一,但在 stackoverflow 上没有其他主题适合。

我的环境是一个 Tomcat 7,它在 context.xml 中定义了一个 JNDI-DataSource。当我启动我的 Tomcat 时,会引发以下异常

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class 'org.apache.derby.jdbc.ClientDataSource' for connect URL 'jdbc:derby://localhost:1527/app;create=true'
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:141)
at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51)
at org.hibernate.tool.hbm2ddl.DatabaseExporter.<init>(DatabaseExporter.java:52)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:367)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:304)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:293)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:498)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1743)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at com.opensolutions.openflow.persistence.DefaultEntityManagerStore.<init>(DefaultEntityManagerStore.java:20)
at com.opensolutions.openflow.servlet.ApplicationWebserviceServlet.initApplication(ApplicationWebserviceServlet.java:38)
at com.opensolutions.openflow.servlet.ApplicationWebserviceServlet.loadBus(ApplicationWebserviceServlet.java:27)
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.init(CXFNonSpringServlet.java:71)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5033)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5317)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1655)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)

Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:289)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
... 37 more

有什么解决办法吗?我不知道。我尝试了很多,但没有任何效果。

4

3 回答 3

1

堆栈跟踪中的这一行是解决问题的关键:

Caused by: java.sql.SQLException: No suitable driver

由于抛出异常org.apache.tomcat...,您似乎没有将数据库驱动程序放在 tomcat 的lib目录中(即您缺少依赖项)。该文件夹存储应用程序所需的外部依赖项,位于apache-tomcat-version/lib/. 您需要为您的 Web 应用程序和 tomcat 服务器提供驱动程序。

另外,看看这些相关的问题:

  1. JDBC/MSQL:找不到合适的驱动程序
  2. 找不到合适的驱动程序的原因
  3. java.sql.SQLException:找不到合适的驱动程序


编辑

问题可能是 webapp 无权访问 library,尝试将 library 添加到tomcat-home-folder/common/lib。我试过了,tomcat7没有公共文件夹,所以我将库放在webapp/WEB-INF/lib中

于 2013-03-26T23:12:31.220 回答
0

你设置了jdbc驱动的路径吗?使用Oracle数据库时,需要将jar文件(jdbc驱动)路径设置为“CLASSPATH”。

于 2020-06-27T13:58:57.470 回答
0

我有一个不正确的 jdbc url,如下所示:

错误的!

jdbc:jtds://myserver:port;databaseName=abc

正确的:

jdbc://myserver:port;databaseName=abc

(删除jtds:部分...)

于 2016-01-20T12:16:49.590 回答