Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. package database;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7.  
  8. public class DatabaseSingleton {
  9.  
  10. private static DatabaseSingleton sing;
  11.  
  12. private final String USERNAME = "thomas.kaviani";
  13. private final String DATABASE = "thomas.kaviani";
  14. private final String PASSWORD = "tucemi23";
  15.  
  16. private Connection connection;
  17.  
  18. private DatabaseSingleton() {
  19.  
  20. }
  21.  
  22. public static DatabaseSingleton getDatabaseSingleton() {
  23. if (sing == null)
  24. sing = new DatabaseSingleton();
  25. return sing;
  26. }
  27.  
  28.  
  29. public Object clone() throws CloneNotSupportedException {
  30. throw new CloneNotSupportedException();
  31.  
  32. }
  33.  
  34. public Connection getConnection(boolean autoCommit) throws SQLException {
  35.  
  36. if (connection == null || connection.isClosed()) {
  37.  
  38. try {
  39. connection = DriverManager.getConnection(
  40. "jdbc:mysql://dt5.ehb.be/"+ DATABASE, USERNAME, PASSWORD);
  41.  
  42. } catch (SQLException ex) {
  43. System.out.println("SQLException: " + ex.getMessage());
  44. System.out.println("SQLState: " + ex.getSQLState());
  45. System.out.println("VendorError: " + ex.getErrorCode());
  46. }
  47. }
  48.  
  49. connection.setAutoCommit(autoCommit);
  50.  
  51. return connection;
  52. }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement