Skip to content

Instantly share code, notes, and snippets.

@rajacsp
Created September 14, 2019 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajacsp/8b0dc26c4e20c43918eecbeec382668c to your computer and use it in GitHub Desktop.
Save rajacsp/8b0dc26c4e20c43918eecbeec382668c to your computer and use it in GitHub Desktop.
MySql Connection Manager with AllowPublicKeyRetrieval False
package com.learned;
import java.sql.Connection;
import java.sql.SQLException;
import com.mysql.cj.jdbc.MysqlDataSource;
public class ConnectionManager {
public static final String serverTimeZone = "UTC";
public static final String serverName = "localhost";
public static final String databaseName ="hive";
public static final int portNumber = 3306;
public static final String user = "raja";
public static final String password = "raja";
public static Connection getConnection() throws SQLException {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUseSSL( false );
dataSource.setServerTimezone( serverTimeZone );
dataSource.setServerName( serverName );
dataSource.setDatabaseName( databaseName );
dataSource.setPortNumber( portNumber );
dataSource.setUser( user );
dataSource.setPassword( password );
dataSource.setAllowPublicKeyRetrieval(true);
return dataSource.getConnection();
}
public static void main(String[] args) {
try {
Connection connection = getConnection();
System.out.println("connection : "+connection);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment