JDBC URL builder
Pick a database and fill in the details to get the JDBC URL, driver class, Maven dependency and Spring Boot properties, with the gotchas for that driver.
HikariCP settings and Maven dependency
JDBC connection strings for the common databases
Every Java application that talks to a relational database needs a JDBC URL, and every vendor invented a different shape for it. PostgreSQL and MySQL use a URL with a query string, SQL Server uses semicolon-separated properties, Oracle has three styles depending on whether you connect by service name, SID or TNS alias, and H2 has in-memory, file and server modes. Remembering all of them is not a good use of anyone's head.
Choose a database, fill in the host, port and database name, and this builder produces the URL, the driver class, the Maven dependency and the Spring Boot properties (including a HikariCP block and the connection test query for that database). Options such as SSL are translated into the correct form for each driver, and the notes under the result flag the traps that are specific to it.
Things people trip over
- SQL Server driver 10 and later encrypts by default, so a server with a self-signed certificate needs
trustServerCertificate=truein development or a real certificate in production. - H2 in-memory databases disappear when the last connection closes unless the URL has
DB_CLOSE_DELAY=-1. - PostgreSQL uses the
publicschema unless you addcurrentSchema. - Oracle publishes ojdbc8 and ojdbc11 jars on Maven Central; choose the one for your JDK.
The builder never contacts your database and nothing you type is uploaded. Test the final URL with your real credentials in your own environment.
Frequently asked questions
What is the format of a JDBC URL?
It starts with jdbc:, then a sub-protocol for the database (postgresql, mysql, oracle:thin, sqlserver, h2), then driver-specific details such as host, port and database name. Each vendor defines its own syntax, which is why they all look different.
Oracle: service name or SID?
Use a service name (jdbc:oracle:thin:@//host:1521/service). The older SID form (@host:1521:SID) only identifies one instance and does not work with pluggable databases or RAC.
Why does SQL Server use semicolons?
Microsoft's driver takes properties as ;name=value pairs after the host and port, not as a query string. Other drivers use ?a=b&c=d.
Should the password go in the URL?
No. Keep it out of the URL, out of source control and out of logs. Read it from an environment variable or a secret store, as the generated Spring properties do with ${DB_PASSWORD}.