[英]How to use CA certificate to connect to database in java
当前,我正在连接到不需要CA证书的数据库,如下所示:
input = new FileInputStream("path/to/properties/file");
prop.load(input);
Class.forName(prop.getProperty("JDBC_DRIVER"));
conn = DriverManager.getConnection(prop.getProperty("DB_URL"), prop.getProperty("USER"), prop.getProperty("PASS"));
现在需求已更改,我必须使用我拥有的CA证书连接到数据库。 现在,我尝试以下操作:
String url = prop.getProperty("DB_URL")+"?verifyServerCertificate=false"+"&useSSL=true"+"&requireSSL=true";
Class.forName(prop.getProperty("JDBC_DRIVER"));
conn = DriverManager.getConnection(url, prop.getProperty("USER"), prop.getProperty("PASS"));
您能否告诉我如何提供CA证书的路径并成功连接到数据库。
我能够弄清楚如何使用SSL(CA证书)连接到数据库:
input = new FileInputStream("path/to/properties/file");
prop.load(input);
Class.forName(prop.getProperty("JDBC_DRIVER"));
System.getProperties().setProperty("javax.net.ssl.trustStore",
"/path_to_certificate");
String url = prop.getProperty("DB_URL")
+ "?verifyServerCertificate=false" + "&useSSL=true"
+ "&requireSSL=true";
return DriverManager.getConnection(url, prop.getProperty("USER"),
prop.getProperty("PASS"));
这个为我工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.