Skip to content

Fix: wrap getConnection() in try/except for DB-API error handling (legacy #218)#70

Open
HenryNebula wants to merge 1 commit intodevfrom
worktree-triage+69-db2-connection-crash
Open

Fix: wrap getConnection() in try/except for DB-API error handling (legacy #218)#70
HenryNebula wants to merge 1 commit intodevfrom
worktree-triage+69-db2-connection-crash

Conversation

@HenryNebula
Copy link
Copy Markdown
Owner

Summary

Fixes #69: Connection failures (SQLException from DriverManager.getConnection()) now properly raise DB-API 2.0 DatabaseError instead of propagating as raw Java exceptions.

The original issue reported a JVM-level crash during DB2 connection. While JVM crashes are outside our control, the connection code was missing proper exception handling for normal connection failures (bad credentials, network errors, etc.).

Changes

  • Wrap DriverManager.getConnection() in try/except with _handle_sql_exception() to map Java SQLExceptions to DB-API 2.0 DatabaseError
  • Add fail-connect URL pattern to MockDriver for simulating connection failures
  • Add mock test verifying connection failure raises DatabaseError
  • Add integration test verifying connection to non-existent HSQLDB server raises DatabaseError

Test plan

  • Added mock test reproducing connection failure exception mapping
  • Added integration test with non-existent HSQLDB server
  • Verified fix passes with CLASSPATH="test/jars/*:test/mock-jars/*" uv run python -m unittest test.test_mock
  • Verified fix passes with CLASSPATH="test/jars/*" uv run python -m unittest test.test_integration.HsqldbTest
  • All 77 tests pass, no regressions

Closes #69

Generated with Claude Code

HenryNebula added a commit that referenced this pull request Apr 26, 2026
…gacy #70)

The fallback path's _to_java() was dropping microseconds when converting
Python datetime to java.sql.Timestamp (%S instead of %S.%f), and
time.isoformat() could produce fractional seconds that java.sql.Time
rejects. Also adds regression tests for datetime/date/time parameter
binding in both mock and integration test suites.

Closes #88

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@HenryNebula HenryNebula force-pushed the worktree-triage+69-db2-connection-crash branch from cec4bf3 to 053c98f Compare April 27, 2026 00:10
…PI error handling

The original issue (legacy #218) reported a JVM-level crash during DB2
connection that could not be caught by Python. While JVM crashes are
outside our control, the connection code was also missing proper exception
handling for normal connection failures (bad credentials, network errors,
etc.). Java SQLExceptions from getConnection() now map to DB-API 2.0
DatabaseError instead of propagating as raw Java exceptions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
HenryNebula added a commit that referenced this pull request Apr 28, 2026
…gacy #70)

The fallback path's _to_java() was dropping microseconds when converting
Python datetime to java.sql.Timestamp (%S instead of %S.%f), and
time.isoformat() could produce fractional seconds that java.sql.Time
rejects. Also adds regression tests for datetime/date/time parameter
binding in both mock and integration test suites.

Closes #88

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@HenryNebula HenryNebula force-pushed the worktree-triage+69-db2-connection-crash branch from 053c98f to d7fe5d6 Compare April 28, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant