通过创建数据源与PostgreSQL 12连接时出错

时间:2020-01-10 12:52:52

标签: postgresql wildfly

通过Wildfly管理控制台创建数据源时,连接到PostgreSQL 12时出现异常。

它在我的另一台装有PostgreSQL 9.5的机器上运行良好。在没有数据源的情况下连接起来似乎工作正常。

  try (Connection conn = DriverManager.getConnection(
            "jdbc:postgresql://127.0.0.1:5432/registrar", "postgres", "postgres")) {

        if (conn != null) {
            System.out.println("Connected to the database!");

            Statement statement = conn.createStatement();
            ResultSet rs = statement.executeQuery("Select * FROM public.user LIMIT 10");

            while(rs.next())
                System.out.println(rs.getString(2));

        } else {
            System.out.println("Failed to make connection!");
        }

但是当我创建这样的数据源时:

enter image description here 这是我尝试从UI测试连接时遇到的异常。

Request
{
    "address" => [
        ("subsystem" => "datasources"),
        ("data-source" => "RegistrarDS")
    ],
    "operation" => "test-connection-in-pool"
}

Response

Internal Server Error
{
    "outcome" => "failed",
    "failure-description" => "WFLYJCA0040: failed to invoke operation: WFLYJCA0047: Connection is not valid",
    "rolled-back" => true,
    "response-headers" => {"process-state" => "reload-required"}
}

PostgreSQL 12中有什么变化吗?可能是什么问题?

1 个答案:

答案 0 :(得分:0)

可能是驱动程序中定义的数据源类出现问题,如Issues.redhat.com上here所述

如果定义了数据源类,则将优先创建数据源,因此它只能使用连接属性。

由于所有驱动程序都没有一个connection-url属性,因此,如果要定义数据源类,则必须使用connection-properties。

您可以尝试的另一件事是设置“连接属性”而不是“连接URL”,并确保您使用的是正确的/最新的驱动程序jar文件。

还请检查您的Postgresql日志以获取有关该异常的更多信息。

-> https://www.postgresql.org/about/news/2000/

相关问题