Java JDBC FAQ: Can you share Java JDBC connection string examples for the most popular relational databases?
Some days we all need something simple, and today I needed the example syntax for a JDBC connection string (the JDBC URL) for MySQL and Postgresql databases. While I was digging through my old examples, I found JDBC connection string examples for other databases, and thought I'd share them all here.
To that end, here are some example Java JDBC connection string examples for various databases, including MySQL, Postgres, SQL Server, and DB2.Back to top
JDBC connection string examples
Here’s a table showing the syntax for JDBC URLs and drivers that I've used on recent projects.
In need of a Java JDBC driver for your database? I thought I'd put together a quick list here showing the URLs where you can download the latest JDBC drivers for databases like Postgresql (Postgres), MySQL, and Microsoft SQL Server.
MySQL JDBC driver
MySQL Connector/J is the official MySQL JDBC driver. Here's a link to their JDBC driver:
Spring JDBC FAQ: How do I retrieve the auto-generated database key for a serial field (also known as an auto_increment field in MySQL) after I perform a SQL INSERT using Spring JDBC?
For some reason I can never remember how to search for database table fields that are either
NOT NULL. I always try to use the
= operator or something else.
So, for myself, here’s an example of how to perform a SQL query and find all records where a field in a database table is
SELECT * FROM foo WHERE bar IS NULL;
And here’s how to perform a SQL query showing all records in a database table where a column is