Connection properties

Let's talk about the connection properties. While connecting to the database using the connection string, as in the earlier examples, you can also set other parameters in addition to standard connection parameters. These properties may be specified in either the connection URL or the additional properties object parameter to DriverManager.getConnection. The following examples illustrate the use of both methods to establish an SSL connection:

String url = "jdbc:postgresql://localhost/postgres"; 
Properties props = new Properties(); 
props.setProperty("user","fred"); 
props.setProperty("password","secret"); 
props.setProperty("ssl","true"); 
Connection conn = DriverManager.getConnection(url, props); 

or

String url = "jdbc:postgresql://localhost/test?user=fred&password=secret&ssl=true"; ...

Get PostgreSQL Development Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.