PostgreSQL wire: Java (pgjdbc)
The only change
Section titled “The only change”# host postgres.internal warehouse.internal# port 5432 5432 (PostgreSQL wire)# user / password / database PostgreSQL values MachWarehouse valuesJDBC URL: jdbc:postgresql://warehouse.internal:5432/demo?sslmode=verify-full.
mvn -q compile exec:javaLibrary: org.postgresql:postgresql 42.7.14, Java 25 LTS.
Source
Section titled “Source”The program as it is kept and tested in the Mach Database Warehouse repository; highlighted lines read the connection setting.
package example;
import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;
/** Aggregates over the PostgreSQL wire with pgjdbc. Plain JDBC code. */public final class Main { private Main() {}
public static void main(String[] args) throws Exception { // Before: jdbc:postgresql://postgres.internal:5432/demo?sslmode=verify-full // After: jdbc:postgresql://warehouse.internal:5432/demo?sslmode=verify-full try (Connection conn = DriverManager.getConnection( System.getenv("JDBC_URL"), System.getenv("DB_USER"), System.getenv("DB_PASSWORD")); Statement st = conn.createStatement(); ResultSet rs = st.executeQuery( "SELECT country, count(*) AS events, sum(revenue) AS revenue FROM events GROUP BY country ORDER BY revenue DESC")) { while (rs.next()) { System.out.printf("%s\t%d\t%s%n", rs.getString(1), rs.getLong(2), rs.getBigDecimal(3)); } } }}<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>example.machwarehouse</groupId> <artifactId>pgjdbc-example</artifactId> <version>1.0.0</version> <properties> <maven.compiler.release>25</maven.compiler.release> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <exec.mainClass>example.Main</exec.mainClass> </properties> <dependencies> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>42.7.14</version> </dependency> </dependencies></project>