Connection to Mysql via SSL

0

Good morning, everyone. I am developing a program to manage a database created in Mysql. My application is in java and to connect to the database at the moment I was using the driver manager of the mysql connector in an insecure way. Now that I have almost finished the program I would like to connect securely to the database via SSL if possible but I do not have much idea of what code I should integrate into my program to be able to do this. Here I leave the fragment of code that I am using to connect to the database. Thank you.

    private void connection() {

        try {
            Class.forName("com.mysql.jdbc.Driver");


            // connect way #1
            //String url1 = "jdbc:mysql://localhost/usuarios";
            String url1 = "jdbc:sqlserver://localhost;" +  
     "databaseName=name;integratedSecurity=true;"; 
            String user = "******";
            String password = "******";

            connection = DriverManager.getConnection(url1, user, password);
            if (connection != null) {
                System.out.println("Connected to PRIVILEGES ACCESS");
                conect = true;
            }

        } catch (SQLException ex) {
            System.out.println("An error occurred. Maybe user/password is invalid");
            ex.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
    
asked by Alberto 08.05.2017 в 11:33
source

1 answer

0

a peer of the forum has put this , is in English but is well understood (You can also help the translator). A summary is that your database has to be compatible with SSL and you have to have the certificate installed. I leave you the official documentation to create the secure connection and commands with a short explanation .

    
answered by 08.05.2017 в 14:18