JDBC Connection URL Format
Fast recall
Quick revision
Core answer
Whether you know the structure of a JDBC URL and that the subprotocol is what routes the URL to the correct registered driver.
Using the wrong port or subprotocol, or forgetting required params (MySQL 8 needs serverTimezone) so the connection silently fails at startup.
Explain that DriverManager loops over registered drivers and asks each one 'can you handle this URL?' — the subprotocol is the match key.
Interview-ready guide
Interview answer
jdbc:postgresql://db.example:5432/shop is a PostgreSQL network URL. jdbc:h2:mem:testdb names an in-memory H2 database and has no host section. A SQL Server URL may use semicolon-separated properties. The jdbc prefix lets DriverManager ask registered drivers whether they understand the URL, but the rest is not one cross-vendor grammar.
JDBC Connection URL Format
Direct Answer
Every JDBC URL starts with jdbc:, followed by a driver-specific subprotocol and syntax. There is no universal requirement that it use ://host:port/database. PostgreSQL and MySQL commonly use that network form, while H2, SQLite, Oracle, SQL Server, and vendor data sources use different forms. Follow the selected driver's documentation.
Code Example
// MySQL — note the params after the ? configure SSL + timezone
String mysql = "jdbc:mysql://localhost:3306/shop?useSSL=false&serverTimezone=UTC";
// PostgreSQL — different default port (5432) and its own params
String pg = "jdbc:postgresql://localhost:5432/shop?sslmode=disable";
// Oracle (thin driver) — uses a SID/service form, not the //host pattern
String ora = "jdbc:oracle:thin:@localhost:1521:XE";
// DriverManager reads the subprotocol ("mysql") to choose the registered driver
try (Connection con = DriverManager.getConnection(mysql, "user", "pass")) {
System.out.println("connected to " + con.getCatalog()); // prints: shop
}
The subprotocol (mysql, postgresql, oracle:thin) is the only part that selects the driver — everything else just locates the database.
Common Mistakes & Pitfalls
- Wrong port: MySQL is
3306, PostgreSQL is5432— mixing them up means the connection times out. - Missing required params: MySQL 8 often needs
serverTimezone; omitting it throws a timezone error on startup. - Typo in the subprotocol:
jdbc:mysq:matches no registered driver, so you getNo suitable driver found. - Hard-coding credentials in the URL: keep username and password out of source control; pass them separately or via config.
- Forgetting the leading
jdbc:: a baremysql://...is not a JDBC URL and will not be recognised.
Check your understanding
Answer these without looking back at the article.
- How does the subprotocol select the driver?
- What are the default ports for MySQL and PostgreSQL?
- Why might a MySQL URL need serverTimezone?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.