Skip to content

Instantly share code, notes, and snippets.

@JuliaKrivonos
Created August 30, 2021 11:24
Show Gist options
  • Select an option

  • Save JuliaKrivonos/1f6ef852c50db22a1c730cffacb9272c to your computer and use it in GitHub Desktop.

Select an option

Save JuliaKrivonos/1f6ef852c50db22a1c730cffacb9272c to your computer and use it in GitHub Desktop.
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