Java, JDBC and Postgres

Enterprise adoption of PostgreSQL is trending upward. When you look at what this permissively licensed, open source database offers, that's not a huge surprise.

Top 5 PostgreSQL features for Java devs

Many of PostgreSQL's compelling features, and especially the following ones, appeal to enterprise Java developers:

  • Extended SQL compliance, including support for the SQL 2011 spec, full text search and common table expressions.
  • Support for multiversion concurrency control to reduce contention, locks and blocks.
  • Advanced indexing options for optimizing large, complex data sets for searching.
  • Full ACID compliance to ensure transactional processing of records.
  • Support for object-oriented data types that support inheritance, polymorphism, composition and method overloading.

Java, PostgreSQL and JDBC tutorial

The first thing you'll learn in this PostgreSQL and Java Database Connectivity (JDBC) tutorial is that most developers simply call it Postgres. The two terms are both interchangeable and official. Use whichever one you feel comfortable with.

The next thing you'll learn is how to connect to a PostgreSQL database from your Java programs and perform CRUD operations.

In fact, that's the majority of the tutorial. Once you master how to connect to a PostgreSQL database with JDBC and do the requisite create, read, update and delete (CRUD) operations, you'll have a strong foundation to explore the aspects of PostgreSQL that apply most specifically to your field of expertise.

How to connect Java to a PostgreSQL database

The steps required to connect a Java application to a PostgreSQL database follow the same pattern as other databases such as MySQL, SQLite and Microsoft's SQL Server. However, there are nuances and PostgreSQL specific configurations that can trip up a Java developer.

While these nuances are all covered in the video, here are the basic, high-level steps this PostgreSQL and JDBC tutorial follows:

  1. Install a PostgreSQL database.
  2. Create a database table named TODO.
  3. Create a Maven-based Java project in Eclipse.
  4. Configure the PostgreSQL JDBC Driver.
  5. Create a Java class that holds PostgreSQL's JDBC URL.
  6. Programmatically create a database table.
  7. Perform the four basic CRUD operations through JDBC.

PostgreSQL is an incredibly powerful database, and Java is an incredibly powerful programming language. When the two are combined through the integration of JDBC, the development of robust and scalable Java applications is the inevitable result.

Cameron McKenzie has been a Java EE software engineer for 20 years. His current specialties include Agile development; DevOps; Spring; and container-based technologies such as Docker, Swarm and Kubernetes.

View All Videos