【问题标题】:Jtds No suitable driver maven tomcat runjtds没有合适的驱动maven tomcat运行
【发布时间】:2013-01-29 01:51:46
【问题描述】:

我遇到了这个小问题:

像这样添加了对我的pom 的依赖

  ....

  <dependency>
    <groupId>net.sourceforge.jtds</groupId>
    <artifactId>jtds</artifactId>
    <version>1.2.6</version>
  </dependency>

.. 已将 Maven 依赖项添加到我的 war 应用程序 build path

我的 context.xml 看起来像:

 <?xml version='1.0' encoding='utf-8'?>
 <Context reloadable="true">
  <Resource name="jdbc/TestDS" auth="Container"
        type="javax.sql.DataSource"
        driverClass="net.sourceforge.jtds.jdbcx.JtdsDataSource"
        url="jdbc:jtds:sqlserver://localhost:1433/testdb"
        username="sa" password=""/>     
</Context>

...

当我执行 mvn tomcat:run 时。我明白了

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class ''   
for connect URL 'jdbc:jtds:sqlserver://localhost:1433/testdb'
.....
Caused by: java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getDriver(DriverManager.java:264)
    at     

org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
    ... 36 more

【问题讨论】:

    标签: maven jndi jtds maven-tomcat-plugin


    【解决方案1】:

    如果您使用 JNDI 定义数据源,则驱动程序必须是 "available to both Tomcat internal classes and to your web application"

    因此,如果您只将驱动程序 jar 添加到您的战争中,Tomcat 将无法找到驱动程序类。

    你可以add the jar to the plugin dependencies

    【讨论】:

    • :) .. 我刚刚打开了提供的链接,并在我的driverClassName 中将driverClass 替换为context.xml 并且一切正常.. 感谢您的链接:) .. 你能编辑一下回复此评论,以便我可以标记
    • 听起来这是一个不同的问题。但是在 Tomcat 类路径上没有可用的 jar 的情况下它可以工作似乎很奇怪。
    • 如果驱动程序在战争中可用,它将起作用。这不是一个好主意,因为通常你的 jdbc 驱动程序必须在 $CATALINA_HOME/lib 中,如果你在 tomcat 级别而不是只为你的 webapp 创建这个资源。
    【解决方案2】:

    看看http://tomcat.apache.org/maven-plugin-2.2/run-mojo-features.html(看看 derby 依赖是如何声明的)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-31
      • 2020-06-25
      • 2017-05-05
      • 1970-01-01
      • 1970-01-01
      • 2020-03-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多