From efa7066fa91ce2bcb04955e2a0e496ed3ec8287e Mon Sep 17 00:00:00 2001 From: zgq Date: Sun, 20 Sep 2026 18:04:52 +0800 Subject: [PATCH] Keep JDBC driver diagnostics out of stderr --- README.md | 2 +- .../main/java/ai/ottermind/sqlx/JdbcWorker.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bf21528..49a10ec 100644 --- a/README.md +++ b/README.md @@ -246,7 +246,7 @@ Rows are streamed without a CLI row limit or silent truncation. The agent's own User data lives in `~/.sqlx/`. Use `--data-dir` or `SQLX_DATA_DIR` for another location. Saved connections use AES-256-GCM with an independently generated local key. Back up the key together with the encrypted data; losing the key prevents decryption. Device identity is generated locally, and this version does not upload device information. -The main executable contains no database drivers. MySQL and PostgreSQL use separate native Rust workers; Oracle and SQL Server use a separate JDBC worker. Downloaded resources are selected from the running CLI version's fixed GitHub Release manifest and verified before use. `--manifest ` selects a particular manifest or local test server. +The main executable contains no database drivers. MySQL and PostgreSQL use separate native Rust workers; Oracle and SQL Server use a separate JDBC worker. The JDBC worker keeps vendor driver logging off, so a failed connection reports only the SQLX error; set `SQLX_JDBC_DEBUG=1` to also see the driver's own diagnostics on stderr. Downloaded resources are selected from the running CLI version's fixed GitHub Release manifest and verified before use. `--manifest ` selects a particular manifest or local test server. Downloads happen on first use and are cached afterwards. Each one prints `Downloading …`, a progress line with speed and estimated time, and a final `Downloaded … in 12.3s (390 KB/s)` line on stderr; the progress line is refreshed only when stderr is a terminal, so piped JSON stays clean. An interrupted transfer is retried up to three times, and re-running a failed command reuses every component that is already installed. To avoid waiting inside the first query or page, fetch components ahead of time: diff --git a/java/jdbc/src/main/java/ai/ottermind/sqlx/JdbcWorker.java b/java/jdbc/src/main/java/ai/ottermind/sqlx/JdbcWorker.java index d22e754..10602c1 100644 --- a/java/jdbc/src/main/java/ai/ottermind/sqlx/JdbcWorker.java +++ b/java/jdbc/src/main/java/ai/ottermind/sqlx/JdbcWorker.java @@ -9,6 +9,9 @@ import java.nio.file.*; import java.sql.*; import java.util.*; +import java.util.logging.Level; +import java.util.logging.LogManager; +import java.util.logging.Logger; public final class JdbcWorker { private static final ObjectMapper JSON = new ObjectMapper(); @@ -17,7 +20,18 @@ public final class JdbcWorker { } private final PrintStream out; JdbcWorker(PrintStream out) { this.out = out; } + /** + * Vendor drivers log connection diagnostics through java.util.logging, which floods + * stderr with dozens of lines when a connection fails. Keep it quiet unless + * SQLX_JDBC_DEBUG is set. + */ + private static void quietDriverLogging() { + if (System.getenv("SQLX_JDBC_DEBUG") != null) return; + LogManager.getLogManager().reset(); + Logger.getLogger("").setLevel(Level.OFF); + } public static void main(String[] args) { + quietDriverLogging(); JdbcWorker worker = new JdbcWorker(System.out); try { worker.emit("ready", "protocol_version", 1);