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"; Connection conn = DriverManager.getConnection(url);
You can go through the driver documentation (https://jdbc.postgresql.org/documentation...