我正在嘗試為我的 HikariCP 池設定各種 PostgreSQL JDBC 驅動程式屬性,但由于某種原因,它表明這些屬性不存在。為什么這樣?我使用了錯誤的引數名稱嗎?
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$0(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)
uj5u.com熱心網友回復:
它給出了該錯誤,因為PGSimpleDataSource沒有屬性database(即它沒有setDatabase(String)方法)。它確實有一個屬性databaseName(setDatabaseName在 中定義BaseDataSource)。此屬性在 JDBC 4.3 規范的第9.6.1節中指定。DataSource
閱讀評論,您似乎將JDBC URL 格式(和連接屬性)的檔案與驅動程式提供的資料源實作中可用的屬性混淆了。需要明確的是,該檔案沒有指定 property database,它僅用database作 JDBC URL 語法中的占位符(如 jdbc:postgresql:// host / database。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/483038.html
標籤:爪哇 PostgreSQL 数据库 hikaricp
上一篇:SQL對表列進行計數
