/*
 * 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 main;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import javax.swing.JOptionPane;

/**
 *
 * @author IAGO
 */
public class connection 
{
    private static final String user = "SYSDBA";
    private static final String password = "masterkey";
    private static final String driverName = "org.firebirdsql.jdbc.FBDriver";
    
    //função que retornará a conexão para o banco de dados...
    public static java.sql.Connection GetConnection()
    {
        java.sql.Connection conn = null;
       
        try
        {
            Properties properties = new Properties();
            
            try (FileInputStream fis = new FileInputStream("../.env")) 
            {
                properties.load(fis);

                Class.forName(driverName);
                conn = DriverManager.getConnection("jdbc:firebirdsql:"+properties.getProperty("FIREBIRD_HOST")+"/"+properties.getProperty("FIREBIRD_PORT")+":"+
                                                   properties.getProperty("FIREBIRD_BASE")+"?lc_ctype=WIN1252",user,password);
            }
        }
        catch(IOException | ClassNotFoundException | SQLException e)
        {
            JOptionPane.showMessageDialog(null, e.toString());
        }
        
        return conn;
    }
}
