Skip to content

fix: load JDBC driver before DriverManager.getConnection in Setup (#1082) - #1091

Open
HusainMain wants to merge 6 commits into
OWASP:devfrom
HusainMain:dev#1082
Open

HusainMain wants to merge 6 commits into
OWASP:devfrom
HusainMain:dev#1082

Conversation

@HusainMain

Copy link
Copy Markdown

Fixes #1082

When Tomcat starts without database.properties, Setup.doPost calls
DriverManager.getConnection() without first loading the JDBC driver class.
Tomcat doesn't auto-register drivers from WEB-INF/lib, so setup fails with
"No suitable driver found".

Added Class.forName(driverType) before DriverManager.getConnection so the
driver is registered before the connection attempt. On ClassNotFoundException,
the error is logged and reported cleanly instead of crashing.

Changes:

  • src/main/java/servlets/Setup.java

Build:

  • mvn compile -Dspotless.check.skip=true passes

@SeanDuggan

Copy link
Copy Markdown
Member

Hi HusainMain,

Spotless:check fails on the new htmlOutput line in the ClassNotFoundException handler (over 100 characters). Running mvn spotless:apply fixes it, and CI will fail until then. Once that is pushed builds should run smoothly.

@HusainMain

Copy link
Copy Markdown
Author

Thanks for the review. Applied the formatting and pushed — lint-java should be green now.

@ismisepaul ismisepaul added this to the 4.0.1 milestone Nov 1, 2026
@HusainMain

Copy link
Copy Markdown
Author

Friendly nudge: the Build and Test run for 99e1ee9 is still waiting for approval from a maintainer, so no checks have run since the dev merge on Nov 1. The previous run on b5b74b3 was fully green. Could someone approve it when convenient? Thanks!

@SeanDuggan

Copy link
Copy Markdown
Member

Thanks for this. The CI problem is fixed on dev (#1116), and I've closed #1115 because it duplicated this PR. This is the one we're keeping for #1082.

Two things before review:

Test. Please add a regression test, or add manual steps to the description: delete database.properties, restart Tomcat, run setup, and check there is no "No suitable driver" error.

Small fix. If the driver can't be loaded, the failure message is shown twice. Setting htmlOutput in the new catch block and then appending to it again below causes this. Dropping one of them fixes it.

I'll approve the CI run if it's waiting.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Setup fails with "No suitable driver found" when Tomcat started without database.properties

3 participants