JDBC Connection Parameters
Fast recall
Quick revision
Core answer
Whether you know the four inputs required to open a connection and the order of the connection lifecycle.
Forgetting the driver dependency, or hard-coding credentials directly in source or a committed properties file.
Mention the driver auto-registers since JDBC 4.0 (no Class.forName) and that credentials should come from config or a secrets manager.
Interview-ready guide
Interview answer
DriverManager.getConnection(url, user, password) is the common teaching form for PostgreSQL or MySQL. H2's in-memory database can be opened with jdbc:h2:mem:test and simple/default credentials. A container-managed DataSource may already hold target and authentication configuration, so application code simply calls dataSource.getConnection(). Therefore the fixed list of exactly four values is not universal.
JDBC Connection Parameters
Direct Answer
A JDBC connection needs a driver that understands the target and enough connection properties for that data source. Common network databases use a JDBC URL, username, and password, but credentials may be optional, obtained through another mechanism, or supplied by a managed DataSource. Embedded databases can need only a URL. TLS, timeouts, database name, and authentication options are driver-specific.
Code Example
// 1) driver JAR on the classpath (auto-registered) — no Class.forName needed
String url = "jdbc:mysql://localhost:3306/shop?serverTimezone=UTC"; // 2 the URL
String user = System.getenv("DB_USER"); // 3 from env/secret, not hard-coded
String pass = System.getenv("DB_PASS"); // 4 from env/secret
try (Connection con = DriverManager.getConnection(url, user, pass)) {
System.out.println("connected: " + con.getMetaData().getDatabaseProductName());
}
A DataSource bundles these four settings and adds pooling, so production code asks the DataSource for connections.
Common Mistakes & Pitfalls
- No driver dependency: missing JAR on the classpath gives
No suitable driver found. - Hard-coded credentials: keep them in env vars or a secrets manager, not in source or committed config.
- Wrong URL params: a missing timezone or SSL option can fail the handshake at startup.
- Using the DB root user for the app: breaks least privilege — give the app its own scoped account.
- Opening per request with DriverManager: use a pooled DataSource instead for any real application.
Check your understanding
Answer these without looking back at the article.
- Is Class.forName needed to register the driver?
- Where should database credentials be stored?
- Why use a DataSource instead of DriverManager?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.