php - 在 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.
...
解决方案
推荐阅读
- angular - 重新加载/刷新指令以在 Angular7 中更新 html 中的视图
- html - 我的 scss 文件无法正确通过,您能说出原因吗?
- apache-camel - 为骆驼 json-validator 组件设置自定义错误消息
- python - DataFrame:列的累积总和,直到达到条件并在新列中返回总和
- spring - Spring security OAuth2 令牌自省
- python - 选择 Python 解释器在 VScode 中不起作用
- scala - Scala 中避免 if-else 阶梯的数据帧设计规则引擎
- javascript - 如何获取动态表数据?
- css - 计算字体大小时的 CSS 验证解析错误
- jenkins - 我如何在 jenkins 中修复这个 kubernetes 插件