为什么 HikariCP 说 "Property database does not exist on target class org.postgresql.ds.PGSimpleDataSource"?
Why does HikariCP say "Property database does not exist on target class org.postgresql.ds.PGSimpleDataSource"?
我正在尝试为我的 HikariCP 池设置各种 PostgreSQL JDBC 驱动程序 properties,但由于某种原因,它声明这些属性不存在。为什么这样?我是否使用了错误的参数名称?
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource
import java.sql.Connection;
import java.sql.SQLException;
public class HikariTest {
public static void main(String[] args) throws SQLException {
HikariConfig config = new HikariConfig();
config.setDataSourceClassName("org.postgresql.ds.PGSimpleDataSource");
config.setUsername("[REDACTED]");
config.setPassword("[REDACTED]");
config.addDataSourceProperty("host", "[REDACTED");
config.addDataSourceProperty("database", "[REDACTED]");
config.addDataSourceProperty("ssl", true);
config.addDataSourceProperty("sslcert", "[REDACTED]");
HikariDataSource ds = new HikariDataSource(config);
Connection conn = ds.getConnection();
}
}
输出:
Exception in thread "main" java.lang.RuntimeException: Property database does not exist on target class org.postgresql.ds.PGSimpleDataSource
at com.zaxxer.hikari.util.PropertyElf.setProperty(PropertyElf.java:127)
at com.zaxxer.hikari.util.PropertyElf.lambda$setTargetFromProperties[=12=](PropertyElf.java:51)
at java.base/java.util.concurrent.ConcurrentHashMap.forEach(ConcurrentHashMap.java:1603)
at java.base/java.util.Properties.forEach(Properties.java:1422)
at com.zaxxer.hikari.util.PropertyElf.setTargetFromProperties(PropertyElf.java:46)
at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:323)
at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:112)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:93)
at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81)
at HikariTest.main(HikariTest.java:21)
它给出了那个错误,因为 PGSimpleDataSource
does not have a property database
(i.e. it doesn't have a setDatabase(String)
method). It does have a property databaseName
(setDatabaseName
defined in BaseDataSource
)。此 属性 在 JDBC 4.3 规范的 9.6.1 DataSource
属性 部分中指定。
阅读评论,您似乎将 JDBC URL format(和连接属性)的文档与驱动程序提供的数据源实现上可用的属性混淆了。需要明确的是,该文档没有指定 属性 database
,它仅使用 database
作为 JDBC URL 语法中的占位符(如在 jdbc:postgresql://主机/数据库.
我正在尝试为我的 HikariCP 池设置各种 PostgreSQL JDBC 驱动程序 properties,但由于某种原因,它声明这些属性不存在。为什么这样?我是否使用了错误的参数名称?
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource
import java.sql.Connection;
import java.sql.SQLException;
public class HikariTest {
public static void main(String[] args) throws SQLException {
HikariConfig config = new HikariConfig();
config.setDataSourceClassName("org.postgresql.ds.PGSimpleDataSource");
config.setUsername("[REDACTED]");
config.setPassword("[REDACTED]");
config.addDataSourceProperty("host", "[REDACTED");
config.addDataSourceProperty("database", "[REDACTED]");
config.addDataSourceProperty("ssl", true);
config.addDataSourceProperty("sslcert", "[REDACTED]");
HikariDataSource ds = new HikariDataSource(config);
Connection conn = ds.getConnection();
}
}
输出:
Exception in thread "main" java.lang.RuntimeException: Property database does not exist on target class org.postgresql.ds.PGSimpleDataSource
at com.zaxxer.hikari.util.PropertyElf.setProperty(PropertyElf.java:127)
at com.zaxxer.hikari.util.PropertyElf.lambda$setTargetFromProperties[=12=](PropertyElf.java:51)
at java.base/java.util.concurrent.ConcurrentHashMap.forEach(ConcurrentHashMap.java:1603)
at java.base/java.util.Properties.forEach(Properties.java:1422)
at com.zaxxer.hikari.util.PropertyElf.setTargetFromProperties(PropertyElf.java:46)
at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:323)
at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:112)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:93)
at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81)
at HikariTest.main(HikariTest.java:21)
它给出了那个错误,因为 PGSimpleDataSource
does not have a property database
(i.e. it doesn't have a setDatabase(String)
method). It does have a property databaseName
(setDatabaseName
defined in BaseDataSource
)。此 属性 在 JDBC 4.3 规范的 9.6.1 DataSource
属性 部分中指定。
阅读评论,您似乎将 JDBC URL format(和连接属性)的文档与驱动程序提供的数据源实现上可用的属性混淆了。需要明确的是,该文档没有指定 属性 database
,它仅使用 database
作为 JDBC URL 语法中的占位符(如在 jdbc:postgresql://主机/数据库.