Postgres Jdbc Driver Today

with your PostgreSQL version. 10. Complete Example (Production-Ready) public class PostgresDao private final HikariDataSource dataSource; public PostgresDao() HikariConfig config = new HikariConfig(); config.setJdbcUrl("jdbc:postgresql://localhost:5432/mydb"); config.setUsername(System.getenv("DB_USER")); config.setPassword(System.getenv("DB_PASS")); config.setMaximumPoolSize(10); config.addDataSourceProperty("cachePrepStmts", "true"); config.addDataSourceProperty("prepStmtCacheSize", "250"); config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); this.dataSource = new HikariDataSource(config);

postgresql-<version>.jar Maven coordinates: postgres jdbc driver

public void close() if (dataSource != null && !dataSource.isClosed()) dataSource.close(); with your PostgreSQL version

// PreparedStatement (preferred) String sql = "SELECT * FROM users WHERE age > ? AND city = ?"; try (PreparedStatement pstmt = conn.prepareStatement(sql)) pstmt.setInt(1, 18); pstmt.setString(2, "Paris"); ResultSet rs = pstmt.executeQuery(); this.dataSource = new HikariDataSource(config)