首页 > 解决方案 > 在 Glassfish 中连接到 mysql

问题描述

我的目标是在 glassfish 服务器上运行 php。我安装了 Quercus 并将其部署为 glassfish 中的应用程序(C:\glassfish4\glassfish\domains\domain1\applications\Quercus)。

现在我尝试连接到mysql。mysql 服务器正在运行并通过命令(mysql -u root -p)验证连接。

下一个 test.php 被创建:

<?php
    $servername="localhost";
    $username="root";
    $password="whatever";
    $conn = new mysqli($servername, $username, $password);
    if (!$conn) {
        die("Failed : " . mysqli.connect_error());
    }
    echo "Connection Successful!";
?>

运行 test.php 会给出以下消息:

Warning: A link to the server could not be established.
url=jdbc:mysql://localhost/?
jdbcCompliantTruncation=false&characterSetResults=ISO885_1&characterEncoding=ISO8859_1&userServerPrepStmts=true
driver=com.mysql.jdbc.Driver com.caucho.quercus.QuercusModuleException:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Connection Successful!

从消息来看,很可能是没有安装mysql jdbc驱动。

我将驱动程序添加到 C:\glassfish4\glassfish\domains\domain1\lib\mysql-connector-java-8.0.11\mysql-connectior-java-8.0.11.jar。我不确定如何从 glassfish 管理控制台添加它。它没有显示在 jdbc>connection pool 下。

第二次编辑(基于评论): jar 文件也被移动到 ...\domain1\lib 和 ...\glassfish\lib 中。完成了完整的系统重启。要添加连接池,我按照以下链接上的说明进行操作: https ://dev.mysql.com/doc/connector-j/5.1/en/connector-j-usagenotes-glassfish-config.html

然后我收到以下错误消息:

HTTP Status 500 - Internal Server Error:
type Exception report
message Internal Server Error
description The server encountered an internal error that prevented it from fulfilling this request.
exception java.lang.IllegalStateException: getoutputStream() has already been called for this response.
...

标签: phpmysqlglassfishquercus

解决方案


推荐阅读