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,

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:

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:

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