简体   繁体   中英

how to connect to mysql with SSL in Netbeans 8.0

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?

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) {
            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM