LakeBase with Java Client
Connecting to LakeBase from a Java client (with Onehouse Catalog)
Use this when your LakeBase Cluster is configured with Onehouse Catalog. Authentication is handled via the username/password shown on the cluster's connection details page, and authorization is controlled by the Onehouse's EKS node role.
Step 1: Add the PostgreSQL JDBC Driver
The standard PostgreSQL JDBC driver is sufficient. Add it to your classpath — for example, download postgresql-<version>.jar from the PostgreSQL JDBC site or add the Maven dependency:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.4</version>
</dependency>
Step 2: Get Connection Details
From the Onehouse console, open the Clusters page, click into your LakeBase cluster, and copy the Endpoint URL, username, and password. Refer to Get Connection Details for more.
If VPN is not enabled, configure a bastion host to reach the cluster. Refer to Connect to your VPC.
Step 3: Connect and Run a Query
import java.sql.*;
import java.util.Properties;
public class LakeBaseClient {
public static void main(String[] args) throws Exception {
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://<cluster-host>:5432/postgres";
Properties props = new Properties();
props.setProperty("user", "<username>");
props.setProperty("password", "<password>");
try (Connection conn = DriverManager.getConnection(url, props);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT 1")) {
while (rs.next()) {
System.out.println(rs.getInt(1));
}
}
}
}
Compile and run:
javac -cp ".:postgresql-42.7.4.jar" LakeBaseClient.java
java -cp ".:postgresql-42.7.4.jar" LakeBaseClient
Connecting to LakeBase from a Java client (with Glue Catalog)
Use this when your LakeBase Cluster is configured with Glue Catalog (without Lake Formation). The connection pattern is identical to the Onehouse Catalog case above — authentication uses the username/password from the cluster page, and authorization is controlled by the Onehouse's EKS node role.
Follow the same Onehouse Catalog steps: use the standard PostgreSQL JDBC driver with credentials from the cluster connection details page.
Connecting to LakeBase from a Java client (with Glue Catalog and Lake Formation)
Use this when your LakeBase Cluster is configured with Glue Catalog and Lake Formation. Authentication is delegated to your corporate identity provider (IdP) via the Onehouse LakeBase JDBC driver, and authorization is enforced by Lake Formation.
Step 1: Download the Onehouse LakeBase JDBC Driver
Download the LakeBase JDBC driver and add it to your classpath. The driver class is ai.onehouse.jdbc.OnehouseDriver, which extends the standard PostgreSQL driver with browser-based authentication.
Step 2: Get Connection Details
From the Onehouse console, open the Clusters page, click into your LakeBase cluster, and copy the Endpoint URL. Refer to Get Connection Details for more.
If VPN is not enabled, configure a bastion host to reach the cluster. Refer to Connect to your VPC.
Step 3: Connect and Run a Query
Set the IdP-specific connection properties for your provider. Refer to Supported Identity Providers for the full list of properties.
The example below uses Azure AD OAuth2:
import java.sql.*;
import java.util.Properties;
public class LakeBaseClient {
public static void main(String[] args) throws Exception {
Class.forName("ai.onehouse.jdbc.OnehouseDriver");
String url = "jdbc:postgresql://<cluster-host>:5432/postgres";
Properties props = new Properties();
// Placeholder user/password — the driver authenticates via the IdP
props.setProperty("user", "user");
props.setProperty("password", "user");
// Browser-based IdP authentication
props.setProperty("browserAuth", "true");
props.setProperty("azureOAuthTenantId", "<tenant-id>");
props.setProperty("azureOAuthClientId", "<client-id>");
props.setProperty("azureOAuthClientSecret", "<client-secret>");
props.setProperty("azureOAuthIamRole",
"arn:aws:iam::<account>:role/<onehouse-lakebase-role>");
System.out.println("Browser will open for OAuth authentication...");
try (Connection conn = DriverManager.getConnection(url, props);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT 1")) {
while (rs.next()) {
System.out.println(rs.getInt(1));
}
}
}
}
Compile and run:
javac -cp ".:lakebase-driver.jar" LakeBaseClient.java
java -cp ".:lakebase-driver.jar" LakeBaseClient
On getConnection(), the driver opens a browser window for the IdP login, starts a local callback server (default port 8888) to receive the response, and then completes the PostgreSQL connection.
Step 4: (Optional) Specify an IAM Role
When using Lake Formation for access control, you can optionally specify an IAM role to assume for querying. If you don't specify a role, the first IAM role from your authentication token is used by default.
To specify a role explicitly, add the options connection property:
props.setProperty("options",
"-c onehouse.lakebase_iam_role=arn:aws:iam::<account>:role/<role-name>");
Or include it in the JDBC URL:
String url = "jdbc:postgresql://<cluster-host>:5432/postgres"
+ "?options=-c onehouse.lakebase_iam_role=arn:aws:iam::<account>:role/<role-name>";