[英]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.