class DBQueries {

    public static int getCountOfDistinctKeys(final String tableName, final Connection connection){
        final String selectSql = String.format("SELECT COUNT(DISTINCT value) FROM cqtbl_%s",tableName);
        Statement statement = null;
        try{
            statement = connection.createStatement();
            java.sql.ResultSet resultSet = statement.executeQuery(selectSql);
            if (!resultSet.next()){
                throw new IllegalStateException("Unable to execute count. The ResultSet returned no row. Query: " + selectSql);
            }

            return resultSet.getInt(1);
        }catch(Exception e){
            DBUtils.closeQuietly(statement);
            throw new IllegalStateException("Unable to count distinct keys.", e);
        }
    }

}