Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package mssql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author Ticu
- */
- public class DatabaseConnection {
- private static DatabaseConnection instance;
- private Connection connection;
- private String url = "jdbc:sqlserver://DESKTOP-G3JRQ2G;databaseName=boeken;user=Ticu;password=Adm123";
- private DatabaseConnection() {
- try {
- this.connection = DriverManager.getConnection(url);
- } catch (SQLException ex) {
- Logger.getLogger(DatabaseConnection.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement