Programming & Development / April 12, 2025

Enum Representation of Districts in Portugal and SQL Table for Storing District Data

Enum District Portugal Java SQL Aveiro Beja Braga Bragança Castelo Branco Coimbra Évora Faro Guarda Leiria Lisbon Madeira Minho Portalegre Porto Santarém Setúbal Viana do Castelo Vila Real Viseu District Code

Enum Representation in Java

Portugal is divided into 18 districts (excluding autonomous regions). Below is an enum representation of those districts with their respective codes:

java

public enum District {
    AVEIRO("AV"),
    BEJA("BE"),
    BRAGA("BR"),
    BRAGANÇA("BA"),
    CASTELO_BRANCO("CB"),
    COIMBRA("CO"),
    ÉVORA("EV"),
    FARO("FA"),
    GUARDA("GU"),
    LEIRIA("LE"),
    LISBON("LI"),
    MADEIRA("MD"),
    MINHO("MI"),
    PORTALEGRE("PA"),
    PORTO("PO"),
    SANTARÉM("SA"),
    SETÚBAL("SE"),
    VIANA_DO_CASTELO("VC"),
    VILA_REAL("VR"),
    VISEU("VI");

    private final String code;

    District(String code) {
        this.code = code;
    }

    public String getCode() {
        return this.code;
    }
}

In the code:

  • The enum District defines the districts of Portugal and their respective codes.
  • Each district is associated with a two-character abbreviation.
  • The getCode() method allows you to retrieve the district code.

SQL Representation for Storing District Data

To store the districts of Portugal in a database, you can create a table and insert the data using the following SQL:

sql

-- Table definition for storing districts of Portugal
CREATE TABLE districts (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    code CHAR(2) NOT NULL
);

-- Inserting data for districts of Portugal
INSERT INTO districts (name, code) VALUES
('Aveiro', 'AV'),
('Beja', 'BE'),
('Braga', 'BR'),
('Bragança', 'BA'),
('Castelo Branco', 'CB'),
('Coimbra', 'CO'),
('Évora', 'EV'),
('Faro', 'FA'),
('Guarda', 'GU'),
('Leiria', 'LE'),
('Lisbon', 'LI'),
('Madeira', 'MD'),
('Minho', 'MI'),
('Portalegre', 'PA'),
('Porto', 'PO'),
('Santarém', 'SA'),
('Setúbal', 'SE'),
('Viana do Castelo', 'VC'),
('Vila Real', 'VR'),
('Viseu', 'VI');

In the SQL:

  • We create a districts table with columns id (auto-incremented), name (the name of the district), and code (the abbreviation for the district).
  • The INSERT INTO statement adds the districts of Portugal along with their respective codes into the table.

This setup allows you to store and retrieve the districts of Portugal easily, both within your Java application (via enums) and in a relational database system.


Comments

No comments yet

Add a new Comment

NUHMAN.COM

Information Technology website for Programming & Development, Web Design & UX/UI, Startups & Innovation, Gadgets & Consumer Tech, Cloud Computing & Enterprise Tech, Cybersecurity, Artificial Intelligence (AI) & Machine Learning (ML), Gaming Technology, Mobile Development, Tech News & Trends, Open Source & Linux, Data Science & Analytics

Categories

Tags

©{" "} Nuhmans.com . All Rights Reserved. Designed by{" "} HTML Codex