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

-


Have Questions? Post them here!

Top Hashtags:

Advertisements

Advertisements




Advertisements