Reputation: 2070
I am trying to connect to a remote mysql server that requires a connection with SSL. I have been provided with a .key, .cert and CA certificate files. I have imported the .cert file into keytools with:
keytool -import -alias mysqlclientcertificate -file mycert.crt
In NetBeans, when I create a new connection using Services->Databases->Drivers->MySQL(Connector/J driver) I am prompted with a panel where I specify the host, the user and password and finally I add connection parameters like:
useSSL = true
requireSSL = true
I think I am missing some step here, but cannot figure out what exactly, and I couldn't find on Google any pointer to solve this issue...
Is there anyone that succeeded in establishing such a connection within NetBeans 8.0?
Upvotes: 0
Views: 2137
Reputation: 582
Try this code
public static void main(String[] args) {
Connection con = null;
try {
String url = "jdbc:mysql://127.0.0.1:3306/dbname"
+ "?verifyServerCertificate=false" + "&useSSL=true"
+ "&requireSSL=true";
String user = "username";
String password = "userpass";
Class dbDriver = Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url, user, password);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (con != null) {
try {
con.close();
} catch (Exception e) {
}
}
}
}
Upvotes: 1