dosubot[bot] commented on issue #2549:
URL:
https://github.com/apache/incubator-hugegraph/issues/2549#issuecomment-2146656274
<!-- Greeting -->
Hey there, @liming1010! I'm here to help you with any bugs, questions, or
contributions. Let's get to the bottom of this together.
<!-- Answer -->
连接 URL 从
`jdbc:postgresql://192.168.105.187:5432/core?currentSchema=hugegraph` 变成
`jdbc:postgresql://192.168.105.187:5432/hugegraph` 的原因是 `PostgresqlSessions`
类中的 `connectDatabase` 方法配置了特定的数据库名称,而这个名称可能在配置中被设置为 `hugegraph`。
要解决这个问题,请确保 `PostgresqlOptions.POSTGRESQL_CONNECT_DATABASE` 的配置被设置为 `core`
而不是 `hugegraph`。这样可以确保连接 URL 保持为
`jdbc:postgresql://192.168.105.187:5432/core?currentSchema=hugegraph`。
以下是相关代码片段:
```java
@Override
protected String connectDatabase() {
return this.config().get(PostgresqlOptions.POSTGRESQL_CONNECT_DATABASE);
}
```
确保配置文件或设置 `HugeConfig` 对象的代码中有正确的数据库名称:
```java
config.set(PostgresqlOptions.POSTGRESQL_CONNECT_DATABASE, "core");
```
此外,在 `DBUtil` 类中,确保 `url` 参数正确设置为包含所需的数据库名称:
```java
public void connect(String database) {
this.close();
String url = String.format("%s/%s?%s", this.url, database,
"useSSL=false");
try {
Class.forName(this.driver);
this.conn = DriverManager.getConnection(url, this.user, this.pass);
} catch (ClassNotFoundException e) {
throw new LoadException("Invalid driver class '%s'", e, this.driver);
} catch (SQLException e) {
throw new LoadException("Failed to connect database via '%s'", e,
this.url);
}
}
```
确保在调用 `connect` 方法时传递正确的数据库名称:
```java
DBUtil dbUtil = new DBUtil(driver, url, user, pass);
dbUtil.connect("core");
```
这样可以防止连接 URL 变成 `jdbc:postgresql://192.168.105.187:5432/hugegraph`
<sup>[[1]](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-server/hugegraph-postgresql/src/main/java/org/apache/hugegraph/backend/store/postgresql/PostgresqlSessions.java)</sup><sup>[[2]](https://github.com/apache/incubator-hugegraph-toolchain/blob/master/hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/DBUtil.java)</sup>.
<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]