ssl连接时如何修复“无法打开jks文件”

时间:2019-10-10 15:53:34

标签: mysql ssl jdbc java-11 truststore

当我尝试与MySQL建立基于JDBC的SSL连接时,出现以下异常:

  

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:无法打开file://home/files/_jvm/bin/keystore.jks [home]

  1. 我试图将所有属性保留在JDBC网址中
  2. 我也尝试传递属性实例
Class.forName("com.mysql.jdbc.Driver");
Properties mysqlProperties = new Properties();
mysqlProperties.put("user", "root");
mysqlProperties.put("password", "root");
mysqlProperties.put("clientCertificateKeyStoreUrl", "file://home/files/_jvm/bin/keystore.jks");
mysqlProperties.put("clientCertificateKeyStorePassword", "mypass");
mysqlProperties.put("trustCertificateKeyStoreUrl", "file://home/files/_jvm/bin//truststore.jks");
mysqlProperties.put("trustCertificateKeyStorePassword", "mypass");
con = DriverManager.getConnection(
    "jdbc:mysql://localhost:3306/db74?verifyServerCertificate=true&useSSL=true&requireSSL=true",
    mysqlProperties);
System.out.println(con.getMetaData().getDatabaseProductName());

我希望通过加密连接[基于SSL / TLS的连接]获得数据库名称。

0 个答案:

没有答案