Programming & Development / April 11, 2025

How to Represent Brazilian States in Java and SQL with Official State Codes

Java enum Brazilian states Brazil ISO 3166-2 BR SQL table enum with code Spring Boot Brazil states insert SQL address validation Brazil state codes Estados do Brasil

Java Enum: Brazilian States with ISO Codes

Below is a Java enum listing all 26 Brazilian states and the Federal District, using their official ISO 3166-2:BR two-letter codes:

java

public enum BrazilianState {
    ACRE("AC"),
    ALAGOAS("AL"),
    AMAPA("AP"),
    AMAZONAS("AM"),
    BAHIA("BA"),
    CEARA("CE"),
    DISTRITO_FEDERAL("DF"),
    ESPIRITO_SANTO("ES"),
    GOIAS("GO"),
    MARANHAO("MA"),
    MATO_GROSSO("MT"),
    MATO_GROSSO_DO_SUL("MS"),
    MINAS_GERAIS("MG"),
    PARA("PA"),
    PARAIBA("PB"),
    PARANA("PR"),
    PERNAMBUCO("PE"),
    PIAUI("PI"),
    RIO_DE_JANEIRO("RJ"),
    RIO_GRANDE_DO_NORTE("RN"),
    RIO_GRANDE_DO_SUL("RS"),
    RONDONIA("RO"),
    RORAIMA("RR"),
    SANTA_CATARINA("SC"),
    SAO_PAULO("SP"),
    SERGIPE("SE"),
    TOCANTINS("TO");

    private final String code;

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

    public String getCode() {
        return code;
    }
}

Usage Example:

java

BrazilianState state = BrazilianState.SAO_PAULO;
System.out.println(state.getCode()); // Outputs: SP

SQL Version: Brazilian States Table

You can represent these states in a relational database with the following table structure and seed data:

sql

CREATE TABLE brazilian_states (
    id SERIAL PRIMARY KEY,
    name VARCHAR(64) NOT NULL,
    code CHAR(2) NOT NULL UNIQUE
);

Insert Statements:

sql

INSERT INTO brazilian_states (name, code) VALUES
('Acre', 'AC'),
('Alagoas', 'AL'),
('Amapá', 'AP'),
('Amazonas', 'AM'),
('Bahia', 'BA'),
('Ceará', 'CE'),
('Distrito Federal', 'DF'),
('Espírito Santo', 'ES'),
('Goiás', 'GO'),
('Maranhão', 'MA'),
('Mato Grosso', 'MT'),
('Mato Grosso do Sul', 'MS'),
('Minas Gerais', 'MG'),
('Pará', 'PA'),
('Paraíba', 'PB'),
('Paraná', 'PR'),
('Pernambuco', 'PE'),
('Piauí', 'PI'),
('Rio de Janeiro', 'RJ'),
('Rio Grande do Norte', 'RN'),
('Rio Grande do Sul', 'RS'),
('Rondônia', 'RO'),
('Roraima', 'RR'),
('Santa Catarina', 'SC'),
('São Paulo', 'SP'),
('Sergipe', 'SE'),
('Tocantins', 'TO');

Summary

With Brazil's 27 federal units, using a Java enum and a relational SQL table ensures strong validation, easy integration, and standardized data handling. These structures are essential for applications involving Brazilian address data, form controls, or region-based logic.


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