Java JDBC Connection with Database using SSL (https) URL


Post Banner

If you are working with JDBC and your Database using SSL, then you can simply add ?autoReconnect=true&useSSL=false to the database connection string,



Example:
private static final String MYSQL_JDBC_DRIVER_CLASS = "com.mysql.cj.jdbc.Driver";
private static final String DB_URL = "jdbc:mysql://localhost:3306/myDb?autoReconnect=true&useSSL=false";
private static final String DB_USER = "root";
private static final String DB_USER_PASSWORD = "root123";

Connection connection = DriverManager.getConnection(DB_URL,DB_USER,DB_USER_PASSWORD);


If you want your Database say MySQL to have SSL enabled then follow this document: https://dev.mysql.com/doc/refman/8.0/en/creating-ssl-files-using-openssl.html

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap