Programming & Development / April 12, 2025

Enum Representation of Cantons in Switzerland and SQL Table for Storing Canton Data

Enum Cantons Switzerland Java SQL Zurich Geneva Bern Vaud Canton Code Administrative Division

✅ Enum Representation in Java

Switzerland is divided into 26 cantons. Below is a Java enum representing each canton with their standard two-letter canton code:

java

public enum Canton {
    AARGAU("AG"),
    APPENZELL_INNERRHODEN("AI"),
    APPENZELL_AUSSERRHODEN("AR"),
    BASEL_LAND("BL"),
    BASEL_CITY("BS"),
    BERN("BE"),
    FRIBOURG("FR"),
    GENÈVE("GE"),
    GLARUS("GL"),
    GRISONS("GR"),
    JURA("JU"),
    LUCERNE("LU"),
    NEUCHÂTEL("NE"),
    NIDWALDEN("NW"),
    OBWALDEN("OW"),
    SCHAFFHAUSEN("SH"),
    SCHWYZ("SZ"),
    SOLTHURN("SO"),
    ST_GALLEN("SG"),
    TICINO("TI"),
    THURGAU("TG"),
    URI("UR"),
    VALAIS("VS"),
    VAUD("VD"),
    ZUG("ZG"),
    ZURICH("ZH");

    private final String code;

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

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

🔹 Notes:

  • Each canton is mapped to its unique two-character code, which is widely recognized in administrative systems and geographic data.
  • The getCode() method provides easy access to the canton abbreviation for database storage or UI display.

✅ SQL Representation for Storing Canton Data

Below is the SQL schema and insert script for storing the 26 cantons of Switzerland:

sql

-- Table definition for Swiss cantons
CREATE TABLE cantons (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    code CHAR(2) NOT NULL
);

-- Insert cantons into the table
INSERT INTO cantons (name, code) VALUES
('Aargau', 'AG'),
('Appenzell Innerrhoden', 'AI'),
('Appenzell Ausserrhoden', 'AR'),
('Basel-Land', 'BL'),
('Basel-City', 'BS'),
('Bern', 'BE'),
('Fribourg', 'FR'),
('Genève', 'GE'),
('Glarus', 'GL'),
('Grisons', 'GR'),
('Jura', 'JU'),
('Lucerne', 'LU'),
('Neuchâtel', 'NE'),
('Nidwalden', 'NW'),
('Obwalden', 'OW'),
('Schaffhausen', 'SH'),
('Schwyz', 'SZ'),
('Solothurn', 'SO'),
('St. Gallen', 'SG'),
('Ticino', 'TI'),
('Thurgau', 'TG'),
('Uri', 'UR'),
('Valais', 'VS'),
('Vaud', 'VD'),
('Zug', 'ZG'),
('Zurich', 'ZH');

This structure makes it easy to handle regional data for Switzerland in Java applications and relational databases.


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