Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package database;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class DatabaseSingleton {
- private static DatabaseSingleton sing;
- private final String USERNAME = "thomas.kaviani";
- private final String DATABASE = "thomas.kaviani";
- private final String PASSWORD = "tucemi23";
- private Connection connection;
- private DatabaseSingleton() {
- }
- public static DatabaseSingleton getDatabaseSingleton() {
- if (sing == null)
- sing = new DatabaseSingleton();
- return sing;
- }
- public Object clone() throws CloneNotSupportedException {
- throw new CloneNotSupportedException();
- }
- public Connection getConnection(boolean autoCommit) throws SQLException {
- if (connection == null || connection.isClosed()) {
- try {
- connection = DriverManager.getConnection(
- "jdbc:mysql://dt5.ehb.be/"+ DATABASE, USERNAME, PASSWORD);
- } catch (SQLException ex) {
- System.out.println("SQLException: " + ex.getMessage());
- System.out.println("SQLState: " + ex.getSQLState());
- System.out.println("VendorError: " + ex.getErrorCode());
- }
- }
- connection.setAutoCommit(autoCommit);
- return connection;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement