java - ssl jdbc connection keystore not found -
i wish use jdbc connect remote mysql database has been secured via ssl. found simple example java program test connection. connection fails , complains keystore file can not found. verify keystore indeed in code. @ least think do. test application looks this:
import java.io.file; import java.sql.*; public class testmysqlssl { public static void main (string[] args) { connection con = null; system.getproperties().setproperty("javax.net.debug","all"); system.getproperties().setproperty("javax.net.ssl.keystore","c:\\liferaystuff\\bundles\\liferay-portal-6.0.6\\tomcat-6.0.29\\jrel.6.0_20\\keystore"); system.getproperties().setproperty("javax.net.ssl.keystorepassword","####"); system.getproperties().setproperty("javax.net.ssl.truststore","c:\\liferaystuff\\bundles\\liferay-portal-6.0.6\\tomcat-6.0.29\\jrel.6.0_20\\truststore"); system.getproperties().setproperty("javax.net.ssl.truststorepassword","####"); try { string url = "jdbc:mysql://xxx.xxx.xxx.xxx:3306/isc"+ "?verifyservercertificate=true"+ "&usessl=true"+ "&requiressl=true"; string user = "*******"; string password = "******"; class dbdriver = class.forname("com.mysql.jdbc.driver"); boolean filelives; filelives = new file("c:/liferaystuff/bundles/liferay-portal-6.0.6/tomcat-6.0.29/jre1.6.0_20/keystore").exists(); system.out.println("keystore " + filelives); con = drivermanager.getconnection(url, user, password); } catch (exception ex) { ex.printstacktrace(); } { if (con != null) { try { con.close(); } catch (exception e){} } } } }
the first bit of output looks this:
keystore true keystore : c:/liferaystuff/bundles/liferay-portal-6.0.6/tomcat-6.0.29/jrel.6.0_20/keystore keystore type : jks keystore provider : default context init failed:java.security.privilegedactionexception:java.io.filenotfoundexception: c:\liferaystuff\bundles\liferay-portal-6.0.6\tomcat-6.0.29\jrel.6.0_20\keystore (the system cannot find path specified) com.mysql.jdbc.communicationsexception: communications link failure due underlyingexception: ** begin nested exception ** com.mysql.jdbc.communicationsexception message: communications link failure due underlying exception: ** begin nested exception **
the keystore file there suspect there may wrong it. running application on windows. there perhaps permission issues file? appreciated.
regards, dave semeraro
it turns out database admin had blocked single ip access server. once ip added able code above work. sorry wasting everyone's time.
Comments
Post a Comment