// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Properties;

public class MainClass {
    public static void main(String[] args) {
        Properties props = new Properties();
        try {
            props.load(new FileInputStream("config.properties"));
        } catch (IOException e) {
            System.err.println("Error reading config.properties: " + e);
            System.exit(1);
        }
        String driver = props.getProperty("db.driver");
        String conurl = props.getProperty("db.conurl");
        String un = props.getProperty("db.un");
        String pw = props.getProperty("db.pw");
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            System.err.println("Error loading driver " + driver + ": " + e);
            System.exit(1);
        }
        DatabaseAccess da = null;
        try {
            da = new DatabaseAccess(conurl, un, pw);
            List<Employee> allemp = da.getAllEmployees();
            for(Employee emp : allemp) {
                System.out.println(emp.getId() + " " + emp.getName());
            }
        } catch (SQLException e) {
            System.err.println("Error in DatabaseAccess: " + e);
        } finally {
            if(da != null) {
                try {
                    da.close();
                } catch (SQLException e) {
                    System.err.println("Error closing DatabaseAccess: " + e);
                }
            }
        }
    }
}
