glassfish mysql 连接被拒绝

问题描述

你好,我正在尝试使用 MysqL 和 glassfish 5.0 作为服务器构建一个应用程序,所以我添加了 jdbc 连接器的 jar 文件并在我的 meta-inf 文件夹中添加一个 context.xml 文件,如下所示:

<Context>
   <Resource name="jdbc/ensasdb" auth="Container" type="javax.sql.DataSource"
          maxActive="50" maxIdle="30" maxWait="10000"
          username="root" password=""
          driverClassName="com.MysqL.jdbc.Driver"
          url="jdbc:MysqL://localhost:3306/ensasdb" />
</Context>

并将其添加到我的 web.xml

<resource-ref>
    <description>MysqL Datasource example</description>
    <res-ref-name>jdbc/ensasdb</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

获取我使用过的数据源

public AdminBean() {
    try {
        Context ctx = new InitialContext();
        ds = (DataSource)ctx.lookup("java:comp/env/jdbc/ensasdb");
    } catch (NamingException e) {
        e.printstacktrace();
    }
}

但我认为这是一个错误

javax.servlet.servletexception:分配连接时出错。原因:无法分配连接,因为:java.net.ConnectException:连接到端口 1,527 上的服务器 localhost 时出错,消息连接被拒绝:connect。

考虑到它在 tomcat 服务器上工作。 提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)