【问题标题】:using GlassFish 4.0 and getting No suitable driver found for jdbc:mysql error使用 GlassFish 4.0 并获得 No suitable driver found for jdbc:mysql 错误
【发布时间】:2013-10-29 04:58:50
【问题描述】:

我得到以下错误;

type Exception report

messageInternal Server Error

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/chh-cw
root cause

java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/chh-cw

以下是我的项目结构:

这是放置外部 jar 的正确路径吗??

【问题讨论】:

    标签: java mysql eclipse jdbc glassfish-4


    【解决方案1】:

    这取决于。谁实际上在创建连接?如果您的应用程序代码是直接的,那么 JAR 属于 WEB-INF/lib。如果您的容器通过 JNDI 资源管理连接,则 JAR 需要位于 Glassfish 类路径中,而不是 WEB-INF/lib。

    在 Glassfish 3.x 中,我将 JAR 放在 domain/lib/ext 或类似的地方。

    【讨论】:

      【解决方案2】:

      是的 - 如果您在可能的 LoginServerlet 中进行连接... 使用这样的代码:

      this.conn = DriverManager.getConnection(getConnString());

      您只需将 mysql..connector.jar 复制到 WEB-Inf/lib 文件夹或您的域。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-12-19
        • 2016-05-07
        • 1970-01-01
        • 2022-01-17
        • 1970-01-01
        • 1970-01-01
        • 2015-10-10
        相关资源
        最近更新 更多