Hi Amine,
In order to test your setup you should try a progressive approach:
1st - Disable SSL on server and connect using 'useSSL=false' on client (mind that default depends on the server version you are connecting to). Fix any issues if any.
2nd - Configure SSL on server and try to connect via client without validating the server certificate, i.e., use 'useSSL=true&verifyServerCertificate=false'. This should be enough to provide a secure connection.
3rd - If the above security level isn't enough for you, then use 'useSSL=true&verifyServerCertificate=true' AND prepare a truststore with the CA certificate (root or any of the intermediates) that can validate the server certificate.
Instead of your Java application, you can also use the mysql client, running on server1, to test this same setup.
Note that the keystore containing the client keys is only needed if the user you are trying to connect was created with some of the options of the REQUIRES clause. Check the documentation for more information:
https://dev.mysql.com/doc/refman/5.7/en/using-encrypted-connections.html#using-encrypted-connections-client-side-configuration
IHTH