首页 > 解决方案 > ssl连接时如何修复“无法打开jks文件”

问题描述

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

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

  1. 我试图将所有属性保留在 JDBC url
  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 的连接]获得数据库名称。

标签: mysqlssljdbcjava-11truststore

解决方案


推荐阅读