package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import org.apache.tomcat.jdbc.pool.DataSource;
import org.apache.tomcat.jdbc.pool.PoolProperties;


public class DBManagement {

    static final String driverClassName="org.mariadb.jdbc.Driver";
    static final String url="jdbc:mariadb://localhost:3306/gdms";
    static final String username="gdms";
    static final String password="GDMS";

    public static DataSource dataSource = new DataSource();

    public void init(){
        PoolProperties poolProperties = new PoolProperties();
        poolProperties.setUrl(url);
        poolProperties.setDriverClassName(driverClassName);
        poolProperties.setUsername(username);
        poolProperties.setPassword(password);
        dataSource.setPoolProperties(poolProperties);
    }
    public static Connection getConnection(){
        try {
            Class.forName(driverClassName);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try {
            return DriverManager.getConnection(url,username,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
