private Connection getConnection()

in application-workloads/jenkins/jenkins-cicd-webapp/src/main/java/com/cvz/azure/DbAccess.java [87:127]


	private Connection getConnection() throws Exception {
		Map<String, String> connData = getConnectionData();
		
		// Initialize connection variables
        String host = connData.get("Data Source");
        String database = connData.get("Database");
        String user = connData.get("User Id");
        String password = connData.get("Password");
        
        // check that the driver is installed
        try
        {
            Class.forName("com.mysql.cj.jdbc.Driver");
        }
        catch (ClassNotFoundException e)
        {
            throw new ClassNotFoundException("MySQL JDBC driver NOT detected in library path.", e);
        }

        // Initialize connection object
        try
        {
            String url = String.format("jdbc:mysql://%s/%s", host, database);
           
            // Set connection properties.
            Properties properties = new Properties();
            properties.setProperty("user", user);
            properties.setProperty("password", password);
            properties.setProperty("useSSL", "true");
            properties.setProperty("verifyServerCertificate", "true");
            properties.setProperty("requireSSL", "false");
            properties.setProperty("serverTimezone", "UTC");

            // get connection
            return DriverManager.getConnection(url, properties);
        }
        catch (SQLException e)
        {
            throw new SQLException("Failed to create connection to database.", e);
        }
	}