Created
September 14, 2019 15:41
-
-
Save rajacsp/8b0dc26c4e20c43918eecbeec382668c to your computer and use it in GitHub Desktop.
MySql Connection Manager with AllowPublicKeyRetrieval False
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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