Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用postgresql连接Wildfly上的数据库时遇到的问题_Java_Postgresql_Wildfly - Fatal编程技术网

Java 使用postgresql连接Wildfly上的数据库时遇到的问题

Java 使用postgresql连接Wildfly上的数据库时遇到的问题,java,postgresql,wildfly,Java,Postgresql,Wildfly,我在使用postgresql连接Wildfly上的数据库时遇到问题,我在Red Hat Core Studio中编写。 我的standalone.xml是: <datasources> <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true" statistics-enabled="$

我在使用postgresql连接Wildfly上的数据库时遇到问题,我在Red Hat Core Studio中编写。
我的standalone.xml是:

<datasources>
         <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true" statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfly.statistics-enabled:false}}">
         <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
              <driver>h2</driver>
              <security>
                   <user-name>sa</user-name>
                   <password>sa</password>
              </security>
          </datasource>
          <datasource jndi-name="java:jboss/datasources/tvTutorial" pool-name="tvTutorial" enabled="true" statistics-enabled="true">
               <connection-url>jdbc:postgresql//localhost:5432/tvTutorial</connection-url>
               <driver-class>org.postgresql.Driver</driver-class>
               <connection-property name="url">
                   jdbc:postgresql//localhost:5432/tvTutorial
               </connection-property>
               <driver>NewPestsList-1.0.war</driver>
               <security>
                   <user-name>user</user-name>
                   <password>password</password>
               </security>
           <validation>
               <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>
                   <background-validation>true</background-validation>
                   <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>
            </validation>
            </datasource>
            <drivers>
                <driver name="h2" module="com.h2database.h2">
                    <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                </driver>
            </drivers>
        </datasources>
    </subsystem>
...
    </deployment>
    </deployments>
</server>
我有一种感觉,这与此有关,但由于我是编程新手,我不确定是否应该添加更多数据,请让我知道

编辑:我在stdunbar的帮助下更新了我的程序,并将T。 还需要学习如何重新安装Wildfly。 现在我得到了这些警告和错误:

WARN  [org.jboss.as.domain.management.security] (MSC service thread 1-1) WFLYDM0111: Keystore C:\Users\david\wildfly-17.0.0.Final\standalone\configuration\application.keystore not found, it will be auto generated on first use with a self signed certificate for host localhost
WARN  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-5) WFLYJCA0003: Unable to instantiate driver class "org.postgresql.Driver": org.jboss.msc.service.DuplicateServiceException: Service jboss.jdbc-driver.NewPestsList-1_0_war_org_postgresql_Driver_42_2 is already registered
ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "NewPestsList-1.0.war")]) - failure description: {
    "WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.jdbc.tvTutorial"],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => [
        "jboss.persistenceunit.\"NewPestsList-1.0.war#tvTutorialPU\".__FIRST_PHASE__ is missing [jboss.naming.context.java.jdbc.tvTutorial]",
        "jboss.persistenceunit.\"NewPestsList-1.0.war#tvTutorialPU\" is missing [jboss.naming.context.java.jdbc.tvTutorial]"
编辑#2:

在我写下正确的地址后,它就起作用了
jdbc/tvTutorial

谢谢你们两位

潜水员必须作为一个模块添加,您不能参考您的作战部署

本指南适用于mysql,但流程相同,只需使用正确的名称即可


潜水员必须作为一个模块添加,您不能参考您的作战部署

本指南适用于mysql,但流程相同,只需使用正确的名称即可


您正在创建一个数据源和一个JDBC连接。你真的只需要数据源。因此,我推荐一种更标准、更不容易出错的方法,而不是手动修改standalone.xml并安装模块。只需提供JDBC驱动程序的副本,就可以编写整个过程的脚本

创建包含以下代码的脚本:

embed-server --server-config=standalone.xml --std-out=echo

batch

# add the module
module add --name=org.postgres --resources=/path/to/postgresql-42.2.8.jar --dependencies=javax.api,javax.transaction.api

# add the driver
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)

# add the datasource
/subsystem=datasources/data-source=tvTutorial/:add(connection-url=jdbc:postgresql://localhost:5432/tvTutorial,driver-name=postgres,jndi-name=java:/jdbc/tvTutorial,user-name=user,password=password)

run-batch
然后使用以下命令运行此命令:

$WILDFLY_HOME/bin/jboss-cli.sh --file=the_file_name.cli
(请注意,$WILDFLY_HOME可能未设置。它只是安装了WILDFLY的目录)

这假定您的发球当前未运行。如果正在运行,则移除前两行和最后一行

您的
persistence.xml
文件现在非常简单,因为配置都通过数据源位于
standalone.xml
中:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
             http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"
             version="2.2">
    <persistence-unit name="tvTutorialPU" transaction-type="JTA">
        <jta-data-source>jdbc/tvTutorial</jta-data-source>
    </persistence-unit>
</persistence>

jdbc/tvb教程
这给了你一个可重复的过程。您现在不必手动修改
standalone.xml
文件,如果您升级了,我已经在Wildfly 8.x到18.x上使用了相同的脚本


我会从新安装的Wildfly开始,因为你不知道所有的东西都被损坏了

您正在创建一个数据源和一个JDBC连接。你真的只需要数据源。因此,我推荐一种更标准、更不容易出错的方法,而不是手动修改standalone.xml并安装模块。只需提供JDBC驱动程序的副本,就可以编写整个过程的脚本

创建包含以下代码的脚本:

embed-server --server-config=standalone.xml --std-out=echo

batch

# add the module
module add --name=org.postgres --resources=/path/to/postgresql-42.2.8.jar --dependencies=javax.api,javax.transaction.api

# add the driver
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)

# add the datasource
/subsystem=datasources/data-source=tvTutorial/:add(connection-url=jdbc:postgresql://localhost:5432/tvTutorial,driver-name=postgres,jndi-name=java:/jdbc/tvTutorial,user-name=user,password=password)

run-batch
然后使用以下命令运行此命令:

$WILDFLY_HOME/bin/jboss-cli.sh --file=the_file_name.cli
(请注意,$WILDFLY_HOME可能未设置。它只是安装了WILDFLY的目录)

这假定您的发球当前未运行。如果正在运行,则移除前两行和最后一行

您的
persistence.xml
文件现在非常简单,因为配置都通过数据源位于
standalone.xml
中:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
             http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"
             version="2.2">
    <persistence-unit name="tvTutorialPU" transaction-type="JTA">
        <jta-data-source>jdbc/tvTutorial</jta-data-source>
    </persistence-unit>
</persistence>

jdbc/tvb教程
这给了你一个可重复的过程。您现在不必手动修改
standalone.xml
文件,如果您升级了,我已经在Wildfly 8.x到18.x上使用了相同的脚本


我会从新安装的Wildfly开始,因为你不知道所有的东西都被损坏了

谢谢你的回复。我取消了驱动程序和数据库的部署,并按照说明进行了操作。仍然有警告:
WARN[org.jboss.as.connector.deployers.jdbc](MSC服务线程1-8)WFLYJCA0003:无法实例化驱动程序类“org.postgresql.driver”:org.jboss.msc.service.DuplicateServiceException:service jboss.jdbc-driver.NewPestsList-1_0_war_org_postgresql_driver_42_2已经注册了
当我取消部署这两个东西时,这个驱动程序不在那里,但当我重新部署时,它回来了。有什么建议可以解决这个问题吗?谢谢你的回复。我取消了驱动程序和数据库的部署,并按照说明进行了操作。仍然有警告:
WARN[org.jboss.as.connector.deployers.jdbc](MSC服务线程1-8)WFLYJCA0003:无法实例化驱动程序类“org.postgresql.driver”:org.jboss.msc.service.DuplicateServiceException:service jboss.jdbc-driver.NewPestsList-1_0_war_org_postgresql_driver_42_2已经注册了
当我取消部署这两个东西时,这个驱动程序不在那里,但当我重新部署时,它回来了。有什么建议可以解决这个问题吗?谢谢你的帮助。现在我已经更新了错误和警告只有一个问题(可能很愚蠢):我还想搜索并向数据库添加数据。为此,我可能需要连接到数据库?我不知道该写在哪里that@Freeky-现在它变得有趣了。我找到了一个可以让你开始的方法。请注意,您的
persistence.xml
已经正确了,所以忽略该部分。JPA是一个非常强大的工具,但有一个初步的学习曲线位。如果你同意这个答案,我将感谢你的支持,并将其标记为接受。然后,如果你被JPA困住了,我会提出一个新问题。现在我已经更新了错误和警告只有一个问题(可能很愚蠢):我还想搜索并向数据库添加数据。为此,我可能需要连接到数据库?我不知道该写在哪里that@Freeky-现在它变得有趣了。我找到了一个可以让你开始的方法。请注意,您的
persistence.xml
已经正确了,所以忽略该部分。JPA是一个非常强大的工具,但有一个初步的学习曲线位。如果你同意这个答案,我将感谢你的支持,并将其标记为接受。然后,如果你被JPA困住了,我会提出一个新问题。