- if (countrycode.length() != cType.getLen()) {
- throw new GigiApiException(SprintfCommand.createSimple("Country code length does not have the required length of {0} characters", Integer.toString(cType.getLen())));
- }
-
- try (GigiPreparedStatement ps = new GigiPreparedStatement(cType.getValidationQuery())) {
- ps.setString(1, countrycode.toUpperCase());
- GigiResultSet rs = ps.executeQuery();
-
- if ( !rs.next()) {
- throw new GigiApiException(SprintfCommand.createSimple("Country code {0} is not available in database", countrycode.toUpperCase()));
- }
- }
- }
-
- public static CountryCode getCountryCode(String countrycode) throws GigiApiException {
- return getCountryCode(countrycode, CountryCodeType.CODE_2_CHARS);
- }
-
- public static CountryCode getCountryCode(String countrycode, CountryCodeType cType) throws GigiApiException {
- if (countrycode.length() != cType.getLen()) {
- throw new GigiApiException(SprintfCommand.createSimple("Country code length does not have the required length of {0} characters", Integer.toString(cType.getLen())));
- }
- try (GigiPreparedStatement ps = new GigiPreparedStatement(cType.getGetQuery())) {
- ps.setString(1, countrycode.toUpperCase());
- GigiResultSet rs = ps.executeQuery();
-
- if ( !rs.next()) {
- throw new GigiApiException(SprintfCommand.createSimple("Country code {0} is not available in database", countrycode.toUpperCase()));
- }
- return new CountryCode(rs.getInt("id"), rs.getString("country"), rs.getString("countrycode"), cType);
- }