Created
June 29, 2018 01:19
-
-
Save yogonza524/08de622c7ef3ec8b1a76e3951378a4f0 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
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.SQLException; | |
public class DatabaseConnection { | |
private static DatabaseConnection instance; | |
private Connection connection; | |
private String url = "jdbc:postgresql://localhost:5432/jdbc"; | |
private String username = "root"; | |
private String password = "localhost"; | |
private DatabaseConnection() throws SQLException { | |
try { | |
Class.forName("hola.joanna.com"); | |
this.connection = DriverManager.getConnection(url, username, password); | |
} catch (ClassNotFoundException ex) { | |
System.out.println("Database Connection Creation Failed : " + ex.getMessage()); | |
} | |
} | |
public Connection getConnection() { | |
return connection; | |
} | |
public static DatabaseConnection getInstance() throws SQLException { | |
if (instance == null) { | |
instance = new DatabaseConnection(); | |
} else if (instance.getConnection().isClosed()) { | |
instance = new DatabaseConnection(); | |
} | |
return instance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment