SQLException:找不到合适的驱动程序

时间:2013-03-26 21:31:20

标签: tomcat sqlexception

这是最主题之一,但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

任何解决方案?我不知道。我尝试了很多,但没有任何作用。

3 个答案:

答案 0 :(得分:1)

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

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

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

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

  1. JDBC/MSQL: No suitable driver found
  2. Cause of No suitable driver found
  3. java.sql.SQLException: No suitable driver found
  4. <小时/> 的修改

    问题可能是webapp没有access to the library,请尝试在tomcat-home-folder/common/lib中添加库。我试过这个并且tomcat7没有公共文件夹,所以我会把库放到webapp / WEB-INF / lib中

答案 1 :(得分:0)

我有一个不正确的jdbc网址:

错!

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

正确:

jdbc://myserver:port;databaseName=abc

(删除jtds:部分...)

答案 2 :(得分:0)

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