Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ris_i_bd;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class DataBase {
- private static final String CONNECTION_STRING = "jdbc:postgresql:ris_i_bd";
- private static final String USER_NAME = "postgres";
- private static final String PASSWORD = "837hfi37all";
- private static Connection connection;
- private DataBase() {
- throw new UnsupportedOperationException();
- }
- static {
- try {
- Class.forName("org.postgresql.Driver");
- } catch (ClassNotFoundException e) {
- throw new RuntimeException(e);
- }
- }
- public static Connection getConnection() {
- if(connection == null) {
- try {
- connection = DriverManager.getConnection(CONNECTION_STRING, USER_NAME, PASSWORD);
- return connection;
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- } else {
- return connection;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement