package com.ferienclub.util;

import java.sql.Connection;
import java.sql.SQLException;

import org.apache.log4j.Logger;

public class DriverManager {

	private static Connection con = null;
	
	private static Logger logger = Logger.getLogger(DriverManager.class);
	
	public static Connection getConnection(){
		if (con == null){
			try {
				Class.forName("net.sourceforge.jtds.jdbc.Driver");
				con = java.sql.DriverManager.getConnection("jdbc:jtds:sqlserver://localhost/FERIENCLUB_SQL;user=sa;password=soa;instance=FERIENCLUB_SQL");
				logger.debug("Created Connection for=\"" + con + "\"");
			} catch (ClassNotFoundException e){
				e.printStackTrace();
			} catch (SQLException e){
				e.printStackTrace();
			}
		}
		return con;
	}
	
	public static void closeConnection(Connection con){
		try {
			con.close();
		} catch (SQLException e){
			e.printStackTrace();
		}
		DriverManager.con = null; 
	}
	
}
