Driver Jdbc Postgresql New! < 2027 >
Requires no native client libraries on the host system.
// Retrieving an Array try (ResultSet rs = stmt.executeQuery("SELECT fruits FROM fruit_basket")) if (rs.next()) java.sql.Array sqlArray = rs.getArray("fruits"); String[] javaArray = (String[]) sqlArray.getArray();
org.postgresql.Driver Maven Central coordinates: org.postgresql:postgresql driver jdbc postgresql
Note the use of try-with-resources blocks. This automatically closes the connection and statement when the block ends, preventing memory leaks.
PostgreSQL arrays are powerful. The driver provides createArrayOf . Requires no native client libraries on the host system
To use the driver in your project, you must add it as a dependency. The most common method is through build tools like or Gradle , where it is hosted on Maven Central. Maven Configuration Add the following to your pom.xml :
Current versions typically support PostgreSQL 8.2 and higher using version 3.0 of the PostgreSQL protocol. Java Versions: Compatible with Java 8 (JDBC 4.2) and above. PostgreSQL arrays are powerful
If you have multiple PostgreSQL servers (Primary/Replica), you can specify them in the URL:
catch (SQLException e) e.printStackTrace();