How to fix the "Cannot open jks file" while ssl connection

Viewed 1672

When I try to make a JDBC-based SSL connection to MySQL, I'm getting the following exception:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Cannot open file://home/files/_jvm/bin/keystore.jks [home]

  1. I tried to keep all properties in JDBC url
  2. I tried passing in properties instance also
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());

I expected to get database name with encrypted connection[ssl/tls based connection].

0 Answers
Related