Enum Class Database

java.lang.Object
java.lang.Enum<Database>
co.mindus.ip2location.Database
All Implemented Interfaces:
Serializable, Comparable<Database>, Constable

public enum Database extends Enum<Database>
Enumeration of available IP2Location LITE database types.

IP2Location provides free LITE databases that are updated on the 1st of each calendar month. Each database type contains different levels of geographic detail, from country-only (DB1) to full location data including timezone information (DB11).

All database types are available in both IPv4-only and IPv6 formats. The IPv6 format contains both IPv4 and IPv6 address mappings but is significantly larger in file size. When IPv6 support is enabled, both databases are downloaded - the IPv4 database for IPv4 lookups and the IPv6 database for IPv6 lookups.

Database Comparison

DatabaseFieldsIPv4 SizeIPv6 Size
DB1Country code, Country name~2 MB~5 MB
DB3+ Region, City~20 MB~50 MB
DB5+ Latitude, Longitude~25 MB~60 MB
DB9+ ZIP code~35 MB~80 MB
DB11+ Timezone~40 MB~90 MB

Feature Queries

Check which fields are available in a database type:

Database db = Database.DB5;
db.hasRegion();      // true
db.hasCity();        // true
db.hasCoordinates(); // true
db.hasZipCode();     // false (requires DB9+)
db.hasTimezone();    // false (requires DB11)

Download Codes

Each database type generates download codes for both IPv4 and IPv6 formats:

// IPv4 download code
Database.DB11.getCode(false);  // "DB11LITEBIN"

// IPv6 download code  
Database.DB11.getCode(true);   // "DB11LITEBINIPV6"

// Full download URL
Database.DB11.getDownloadUrl("YOUR_TOKEN", false);
// https://www.ip2location.com/download?token=YOUR_TOKEN&amp;file=DB11LITEBIN
Author:
Christopher Mindus
See Also:
  • Enum Constant Details

    • DB1_LITE

      public static final Database DB1_LITE
      DB1: Country only.

      Available fields:

      • Country code (ISO 3166-1 alpha-2)
      • Country name

      This is the smallest and fastest database, suitable when only country-level information is needed.

    • DB3_LITE

      public static final Database DB3_LITE
      DB3: Country, Region, City.

      Available fields:

      • Country code and name
      • Region/state name
      • City name
    • DB5_LITE

      public static final Database DB5_LITE
      DB5: Country, Region, City, Coordinates.

      Available fields:

      • Country code and name
      • Region/state name
      • City name
      • Latitude (decimal degrees, -90 to 90)
      • Longitude (decimal degrees, -180 to 180)
    • DB9_LITE

      public static final Database DB9_LITE
      DB9: Country, Region, City, Coordinates, ZIP.

      Available fields:

      • All DB5 fields
      • ZIP/postal code
    • DB11_LITE

      public static final Database DB11_LITE
      DB11: Full database with all LITE fields.

      Available fields:

      • All DB9 fields
      • Timezone (tz database format, e.g., "America/New_York")

      This is the most comprehensive free database available from IP2Location.

  • Method Details

    • values

      public static Database[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static Database valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • getType

      public int getType()
      Returns the database type number.

      The type indicates the level of detail:

      • 1 = Country only
      • 3 = + Region, City
      • 5 = + Latitude, Longitude
      • 9 = + ZIP code
      • 11 = + Timezone
      Returns:
      The database type (1, 3, 5, 9, or 11)
    • getCode

      public String getCode(boolean isIPv6)
      Returns the download code for the IP2Location download API.

      This code is used in the download URL:

      https://www.ip2location.com/download?token=TOKEN&file=CODE

      Examples:

      • getCode(false) returns "DB11LITEBIN" for IPv4
      • getCode(true) returns "DB11LITEBINIPV6" for IPv6
      Parameters:
      isIPv6 - true for IPv6 database code, false for IPv4
      Returns:
      The download code (e.g., "DB11LITEBIN" or "DB11LITEBINIPV6")
    • getDownloadUrl

      public String getDownloadUrl(String token, boolean isIPv6)
      Returns the full download URL for this database.

      Constructs a complete URL that can be used to download the database file.

      Parameters:
      token - The download token for IP2Location API authentication
      isIPv6 - true for IPv6 database, false for IPv4
      Returns:
      The complete download URL
      Throws:
      NullPointerException - if token is null
    • getDescription

      public String getDescription()
      Returns a human-readable description of the database contents.
      Returns:
      Description of included fields (e.g., "Country+Region+City+LatLon+ZIP+Timezone")
    • isLite

      public boolean isLite()
      Gets the flag indicating this is a "LITE" database type that is updated once a month.

      The fully-paid versions of the databases are updated more often, there are more of them, and contain a lot more information in the returned results.

    • hasRegion

      public boolean hasRegion()
      Returns whether this database includes region/state information.
      Returns:
      true if region data is available (type >= 3)
    • hasCity

      public boolean hasCity()
      Returns whether this database includes city information.
      Returns:
      true if city data is available (type >= 3)
    • hasCoordinates

      public boolean hasCoordinates()
      Returns whether this database includes latitude and longitude.
      Returns:
      true if coordinates are available (type >= 5)
    • hasZipCode

      public boolean hasZipCode()
      Returns whether this database includes ZIP/postal code.
      Returns:
      true if ZIP code is available (type >= 9)
    • hasTimezone

      public boolean hasTimezone()
      Returns whether this database includes timezone information.
      Returns:
      true if timezone is available (type >= 11)
    • fromType

      public static Database fromType(int type)
      Finds a database by its type number.
      Parameters:
      type - The database type (1, 3, 5, 9, or 11)
      Returns:
      The matching database
      Throws:
      IllegalArgumentException - if the type is invalid
    • fromCode

      public static Database fromCode(String code)
      Finds a database by its download code.

      Accepts both IPv4 and IPv6 codes (e.g., "DB11LITEBIN" or "DB11LITEBINIPV6") and returns the corresponding database type.

      Parameters:
      code - The download code to search for, case-insensitive
      Returns:
      The matching database
      Throws:
      IllegalArgumentException - if no database matches the code
      NullPointerException - if code is null
    • toString

      public String toString()
      Returns a string representation of this database.
      Overrides:
      toString in class Enum<Database>
      Returns:
      String in format "DB11 (Country+Region+City+LatLon+ZIP+Timezone)"