public static Map mapFromDatabase(String url, String user, String password) {

        Connection c = null;
        Statement stmt = null;
        Map imagesTags = new HashMap();

        try {
            /* Connect to database */
            Class.forName("org.postgresql.Driver");
            c = DriverManager.getConnection(url, user, password);
            c.setAutoCommit(false);

            /* Successful! */
            if (PRINT == 1)
                System.out.println("Database connection successful. Creating map...\n");

            /* Read images (their ids) and their tags from the database and saves them to a map */
            stmt = c.createStatement();
            String theQuery = "SELECT \n" +
                    "  \"imagefiltred\".id, \n" +
                    "  \"imagetagfiltred\".tag \n" +
                    "FROM \n" +
                    "\"Tag\", \n" +
                    "\"imagefiltred\", \n" +
                    "\"imagetagfiltred\"\n" +
                    "WHERE \n" +
                    "  \"imagefiltred\".id = \"imagetagfiltred\".imageid AND\n" +
                    "  \"Tag\".text = \"imagetagfiltred\".tag AND\n" +
                    "  \"Tag\".gettytag = true AND\n" +
                    "  \"imagefiltred\".lat >= 50 AND \n" +
                    "  \"imagefiltred\".lat <= 55 AND \n" +
                    "  \"imagefiltred\".lon >= 5 AND \n" +
                    "  \"imagefiltred\".lon <= 15";
            ResultSet rs = stmt.executeQuery(theQuery);

            /* Write into the Map */
            while (rs.next()) {
                String id = rs.getString("id");
                String tag = rs.getString("tag");

                /* If the Map doesn't already contain the key */
                if (!imagesTags.containsKey(id)) {
                    /* add the key and create internal list */
                    imagesTags.put(id, new ArrayList());

                    /* add the first tag to the internal list */
                    List internal = (ArrayList) imagesTags.get(id);
                    internal.add(tag);
                } else {
                    /* Key already exists for the image; Search for tag in the internal list and add it */
                    List internal = (ArrayList) imagesTags.get(id);
                    if (!(internal.contains(tag))) {
                        internal.add(tag);
                    }
                }
            }

            if (PRINT == 1)
                System.out.println("The map was successfully created.\n");

            /* close reading */
            rs.close();
            stmt.close();

            /* close connection */
            c.close();

        } catch (Exception e) {
            e.printStackTrace();
            System.err.println(e.getClass().getName() + " - " + e.getMessage());
            System.exit(0);
        }

        return imagesTags;

    }