Enum Class Database
- All Implemented Interfaces:
Serializable, Comparable<Database>, Constable
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
| Database | Fields | IPv4 Size | IPv6 Size |
|---|---|---|---|
| DB1 | Country 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&file=DB11LITEBIN
- Author:
- Christopher Mindus
- See Also:
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E>Enum Constant Summary
Enum ConstantsMethod Summary
Modifier and TypeMethodDescriptionstatic DatabaseFinds a database by its download code.static DatabasefromType(int type) Finds a database by its type number.getCode(boolean isIPv6) Returns the download code for the IP2Location download API.Returns a human-readable description of the database contents.getDownloadUrl(String token, boolean isIPv6) Returns the full download URL for this database.intgetType()Returns the database type number.booleanhasCity()Returns whether this database includes city information.booleanReturns whether this database includes latitude and longitude.booleanReturns whether this database includes region/state information.booleanReturns whether this database includes timezone information.booleanReturns whether this database includes ZIP/postal code.booleanisLite()Gets the flag indicating this is a "LITE" database type that is updated once a month.toString()Returns a string representation of this database.static DatabaseReturns the enum constant of this class with the specified name.static Database[]values()Returns an array containing the constants of this enum class, in the order they are declared.
Enum Constant Details
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
DB3: Country, Region, City.Available fields:
- Country code and name
- Region/state name
- City name
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
DB9: Country, Region, City, Coordinates, ZIP.Available fields:
- All DB5 fields
- ZIP/postal code
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
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
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 nameNullPointerException- 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
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 IPv4getCode(true)returns "DB11LITEBINIPV6" for IPv6
- Parameters:
isIPv6-truefor IPv6 database code,falsefor IPv4- Returns:
- The download code (e.g., "DB11LITEBIN" or "DB11LITEBINIPV6")
getDownloadUrl
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 authenticationisIPv6-truefor IPv6 database,falsefor IPv4- Returns:
- The complete download URL
- Throws:
NullPointerException- if token is null
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:
trueif region data is available (type >= 3)
hasCity
public boolean hasCity()Returns whether this database includes city information.- Returns:
trueif city data is available (type >= 3)
hasCoordinates
public boolean hasCoordinates()Returns whether this database includes latitude and longitude.- Returns:
trueif coordinates are available (type >= 5)
hasZipCode
public boolean hasZipCode()Returns whether this database includes ZIP/postal code.- Returns:
trueif ZIP code is available (type >= 9)
hasTimezone
public boolean hasTimezone()Returns whether this database includes timezone information.- Returns:
trueif timezone is available (type >= 11)
fromType
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
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 codeNullPointerException- if code is null
toString