Created
August 30, 2021 11:24
-
-
Save JuliaKrivonos/1f6ef852c50db22a1c730cffacb9272c to your computer and use it in GitHub Desktop.
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 org.jazzteam.fitnesclub.repository.jdbc; | |
| import lombok.extern.slf4j.Slf4j; | |
| import java.sql.Connection; | |
| import java.sql.DriverManager; | |
| import java.sql.SQLException; | |
| @Slf4j | |
| public class ConnectionUtil { | |
| private static final String URL = "datasource.url"; | |
| private static final String USER_NAME = "datasource.username"; | |
| private static final String PASSWORD = "datasource.password"; | |
| private static final String DRIVER = "datasource.driver"; | |
| public static Connection getConnection() { | |
| try { | |
| Class.forName(PropertyUtil.getProperty(DRIVER)); | |
| return DriverManager.getConnection( | |
| PropertyUtil.getProperty(URL), | |
| PropertyUtil.getProperty(USER_NAME), | |
| PropertyUtil.getProperty(PASSWORD)); | |
| } catch (ClassNotFoundException e) { | |
| log.error(e.getMessage()); | |
| throw new IllegalStateException("Cannot find class PropertyUtil.getProperty(DRIVER)" + e.getMessage()); | |
| } catch (SQLException throwables) { | |
| log.error(throwables.getMessage()); | |
| throw new IllegalStateException("SQLException in trying get connection"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment