import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Properties; import org.postgresql.Driver; import org.postgresql.ssl.NonValidatingFactory; import org.postgresql.ssl.ValidatingFactory; public class Client { public static void main(String[] a) throws Exception { // Load the drive class to register jdbc Class c = Driver.class; String url = "jdbc:postgresql://HOST/DB"; Properties props = new Properties(); props.setProperty("user","--ID--"); props.setProperty("password","--PASSWORD--"); props.setProperty("ssl", "true"); // validation args. the options are all options. for defaults, read the code. props.setProperty("sslfactory", ValidatingFactory.class.getName()); props.setProperty(ValidatingFactory.SSL_KEYSTORE_PASSWORD, "--PASSWORD--"); props.setProperty(ValidatingFactory.SSL_PROTOCOL, "TLS"); // or SSLv3, SSLv2,SSlv1 props.setProperty(ValidatingFactory.SSL_KEYSTORE_TYPE, "JKS"); // or PKCS12,JCEKS(?) props.setProperty(ValidatingFactory.SSL_FILE_KEYSTORE, "--FILE--"); Connection conn = DriverManager.getConnection(url, props); Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("SELECT version();"); while (rs.next()) { System.out.println(rs.getString(1)); } rs.close(); st.close(); conn.close(); } }