gpt4 book ai didi

mysql - 无法让 glassfish 连接到 mysql

转载 作者:行者123 更新时间:2023-11-29 00:28:19 24 4
gpt4 key购买 nike

SEVERE: Local Exception Stack: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseExceptionInternal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused.Error Code: 0

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="HelloWorld">
<class>model.HelloWorld</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/database" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="password" />
</properties>
</persistence-unit>
</persistence>

我在 glassfish 上安装了连接器,ping 成功后我只是无法让 servlet 和 entitymanager 获取对 mysql 服务器的查询。任何帮助都会很好,教程也是如此。

最佳答案

如果您正在使用 Glassfish 启动的 JDBC 连接(我认为您是因为您说您已成功 ping 数据源),那么您不想定义 persistence.xml 中的属性。您只想通过 JNDI 名称指定数据源。

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

<persistence-unit name="HelloWorld">
<non-jta-data-source>jdbc/myds</non-jta-data-source>
<class>model.HelloWorld</class>
<properties>
</properties>
</persistence-unit>

</persistence>

关于mysql - 无法让 glassfish 连接到 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17895263/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com