Example usage for java.sql ResultSet toString

List of usage examples for java.sql ResultSet toString

Introduction

In this page you can find the example usage for java.sql ResultSet toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:sec.project.controller.UserController.java

private List<Signup> listSignups(String userName) {
    List<Signup> signups = new ArrayList<>();
    // harcoded for now...
    String databaseAddress = "jdbc:h2:mem:TEST";
    Connection connection = null;
    ResultSet resultSet = null;

    try {/*ww  w .j  a v  a 2  s  . co m*/
        connection = DriverManager.getConnection(databaseAddress, "sa", "");
        Statement s = connection.createStatement();
        // Execute query and retrieve the query results
        resultSet = connection.createStatement()
                .executeQuery("SELECT * from signup where name='" + userName + "'");
        while (resultSet.next()) {
            String address = resultSet.getString("address");
            String name = resultSet.getString("name");
            int id = resultSet.getInt("id");
            int accountId = resultSet.getInt("account_id");
            signups.add(new Signup(name, address));
            System.out.println(resultSet.toString() + address + " " + name + " " + id + " " + accountId);
        }

    } catch (SQLException ex) {
        Logger.getLogger(UserController.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            if (resultSet != null) {
                resultSet.close();
            }
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException ex) {
            Logger.getLogger(UserController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return signups;
}

From source file:BQJDBC.QueryResultTest.QueryResultTest.java

@Test
public void QueryResultTest03() {
    final String sql = "SELECT COUNT(DISTINCT web100_log_entry.connection_spec.remote_ip) AS num_clients FROM [guid754187384106:m_lab.2010_01] "
            + "WHERE IS_EXPLICITLY_DEFINED(web100_log_entry.connection_spec.remote_ip) AND IS_EXPLICITLY_DEFINED(web100_log_entry.log_time) "
            + "AND web100_log_entry.log_time > 1262304000 AND web100_log_entry.log_time < 1262476800";
    final String description = "A sample query from google, but we don't have Access for the query table #ERROR #accessDenied #403";

    this.logger.info("Test number: 03");
    this.logger.info("Running query:" + sql);
    this.logger.debug(description);
    java.sql.ResultSet result = null;
    try {/*from   w ww  . j a  v  a  2s  .c  o m*/
        Statement stmt = con.createStatement();
        //stmt.setQueryTimeout(60);
        result = stmt.executeQuery(sql);
    } catch (SQLException e) {
        this.logger.debug("SQLexception" + e.toString());
        //fail("SQLException" + e.toString());
        Assert.assertTrue(e.getCause().toString()
                .contains("Access Denied: Table measurement-lab:m_lab.2010_01: QUERY_TABLE"));
    }
    logger.info("QueryResult03 result is" + result.toString());
}

From source file:net.agmodel.metbroker.driver.impl.JmaGsmJp.java

/**
 * get database connection and execute SQL command.
 * And put the result to Sequence Object
 * @param seqMap Sequence Map/*from   w  w w. j av a2  s  .  c om*/
 * @param stationId station id
 * @param query SQL statement
 * @param start start date
 * @param end end date
 * @param hourly if true, use SIX_HOURS, else ONE_DAY
 * @throws DriverException something fail.
 */
private void queryTable(StationDataSetProxy seqMap, String stationId, String query, Date start, Date end,
        boolean hourly) throws DriverException {
    Connection con = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    java.sql.Timestamp startDate = new java.sql.Timestamp(start.getTime());
    java.sql.Timestamp endDate = new java.sql.Timestamp(end.getTime());
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));

    try {
        con = dataSource.getConnection();

        logger.debug("Connection: " + con.toString());

        /*         stmt = con.prepareStatement(query);
                 stmt.setInt(1, new Integer(stationId).intValue());
                 stmt.setTimestamp(2, startDate, cal);
                 stmt.setTimestamp(3, endDate, cal);
                 stmt.setInt(4, new Integer(stationId).intValue());
                 stmt.setTimestamp(5, startDate, cal);
                 stmt.setTimestamp(6, endDate, cal);
        */
        stmt = con.prepareStatement(query);
        stmt.setInt(1, new Integer(stationId).intValue());
        stmt.setTimestamp(2, startDate);
        stmt.setTimestamp(3, endDate);
        stmt.setInt(4, new Integer(stationId).intValue());
        stmt.setTimestamp(5, startDate);
        stmt.setTimestamp(6, endDate);
        rs = stmt.executeQuery();

        logger.debug("ResultSet: " + rs.toString());

        AirTemperature tempSequence = null;
        if (seqMap.containsKey(MetElement.AIRTEMPERATURE)) {
            tempSequence = (AirTemperature) seqMap.getSequence(MetElement.AIRTEMPERATURE);
        }
        Rain rainSequence = null;
        if (seqMap.containsKey(MetElement.RAIN)) {
            rainSequence = (Rain) seqMap.getSequence(MetElement.RAIN);
        }
        Humidity humiditySequence = null;
        if (seqMap.containsKey(MetElement.HUMIDITY)) {
            humiditySequence = (Humidity) seqMap.getSequence(MetElement.HUMIDITY);
        }
        Wind windSequence = null;
        if (seqMap.containsKey(MetElement.WIND)) {
            windSequence = (Wind) seqMap.getSequence(MetElement.WIND);
        }

        while (rs.next()) {
            java.util.Date recordTime = null;
            MutableInterval dataInterval = new MutableInterval();
            recordTime = rs.getTimestamp("end_date");

            if (hourly) {
                dataInterval.set(Duration.SIX_HOURS, recordTime);
            } else {
                dataInterval.set(Duration.ONE_DAY, recordTime);
            }

            if (seqMap.containsKey(MetElement.AIRTEMPERATURE)) {
                float dummy = (float) (rs.getFloat("temperature") - 273.15);
                if (!rs.wasNull()) {
                    ((AirTempMaxMinMeanImpl) tempSequence).putMeanOverInterval(dataInterval, dummy);
                }
            }
            if (seqMap.containsKey(MetElement.RAIN)) {
                float dummy = rs.getFloat("total_preciptasion");
                if (!rs.wasNull()) {
                    ((RainImpl) rainSequence).putRainfallOverInterval(dataInterval, dummy);
                }
            }
            if (seqMap.containsKey(MetElement.HUMIDITY)) {
                float dummy = rs.getFloat("relative_humidity");
                if (!rs.wasNull()) {
                    ((RHImpl) humiditySequence).putRHOverInterval(dataInterval, dummy);
                }
            }
            if (seqMap.containsKey(MetElement.WIND)) {
                float u = rs.getFloat("u_wind");
                if (!rs.wasNull()) {
                    float v = rs.getFloat("v_wind");
                    if (!rs.wasNull()) {
                        ((Wind2DImpl) windSequence).putSpeedOverInterval(dataInterval, v, u);
                    }
                }
            }
        }
    } catch (SQLException s) {
        s.printStackTrace();
    } finally {
        try {
            rs.close();
        } catch (Exception s) {
        }
        try {
            stmt.close();
        } catch (Exception s) {
        }
        try {
            con.close();
        } catch (Exception e) {
        }

    }

}

From source file:net.agmodel.metbroker.driver.impl.JmaGsmGl.java

/**
 * get database connection and execute SQL command.
 * And put the result to Sequence Object
 * @param seqMap Sequence Map//from  w  w  w  .ja va 2s  . c om
 * @param stationId station id
 * @param query SQL statement
 * @param start start date
 * @param end end date
 * @param hourly if true, use SIX_HOURS, else ONE_DAY
 * @throws DriverException something fail.
 */
private void queryTable(StationDataSetProxy seqMap, String stationId, String query, Date start, Date end,
        boolean hourly) throws DriverException {
    Connection con = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    java.sql.Timestamp startDate = new java.sql.Timestamp(start.getTime());

    java.sql.Timestamp endDate = new java.sql.Timestamp(end.getTime());
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));

    try {
        con = dataSource.getConnection();

        logger.debug("Connection: " + con.toString());

        /*         stmt = con.prepareStatement(query);
                 stmt.setInt(1, new Integer(stationId).intValue());
                 stmt.setTimestamp(2, startDate, cal);
                 stmt.setTimestamp(3, endDate, cal);
                 stmt.setInt(4, new Integer(stationId).intValue());
                 stmt.setTimestamp(5, startDate, cal);
                 stmt.setTimestamp(6, endDate, cal);
        */
        stmt = con.prepareStatement(query);
        stmt.setInt(1, new Integer(stationId).intValue());
        stmt.setTimestamp(2, startDate);
        stmt.setTimestamp(3, endDate);
        stmt.setInt(4, new Integer(stationId).intValue());
        stmt.setTimestamp(5, startDate);
        stmt.setTimestamp(6, endDate);

        rs = stmt.executeQuery();

        logger.debug("ResultSet: " + rs.toString());

        AirTemperature tempSequence = null;
        if (seqMap.containsKey(MetElement.AIRTEMPERATURE)) {
            tempSequence = (AirTemperature) seqMap.getSequence(MetElement.AIRTEMPERATURE);
        }
        Rain rainSequence = null;
        if (seqMap.containsKey(MetElement.RAIN)) {
            rainSequence = (Rain) seqMap.getSequence(MetElement.RAIN);
        }
        Humidity humiditySequence = null;
        if (seqMap.containsKey(MetElement.HUMIDITY)) {
            humiditySequence = (Humidity) seqMap.getSequence(MetElement.HUMIDITY);
        }
        Wind windSequence = null;
        if (seqMap.containsKey(MetElement.WIND)) {
            windSequence = (Wind) seqMap.getSequence(MetElement.WIND);
        }

        while (rs.next()) {
            java.util.Date recordTime = null;
            MutableInterval dataInterval = new MutableInterval();
            recordTime = rs.getTimestamp("end_date");

            if (hourly) {
                dataInterval.set(Duration.SIX_HOURS, recordTime);
            } else {
                dataInterval.set(Duration.ONE_DAY, recordTime);
            }
            if (seqMap.containsKey(MetElement.AIRTEMPERATURE)) {
                float dummy = (float) (rs.getFloat("temperature") - 273.15);
                if (!rs.wasNull()) {
                    ((AirTempMaxMinMeanImpl) tempSequence).putMeanOverInterval(dataInterval, dummy);
                }
            }
            if (seqMap.containsKey(MetElement.RAIN)) {
                float dummy = rs.getFloat("total_preciptasion");
                if (!rs.wasNull()) {
                    ((RainImpl) rainSequence).putRainfallOverInterval(dataInterval, dummy);
                }
            }
            if (seqMap.containsKey(MetElement.HUMIDITY)) {
                float dummy = rs.getFloat("relative_humidity");
                if (!rs.wasNull()) {
                    ((RHImpl) humiditySequence).putRHOverInterval(dataInterval, dummy);
                }
            }
            if (seqMap.containsKey(MetElement.WIND)) {
                float u = rs.getFloat("u_wind");
                if (!rs.wasNull()) {
                    float v = rs.getFloat("v_wind");
                    if (!rs.wasNull()) {
                        ((Wind2DImpl) windSequence).putSpeedOverInterval(dataInterval, v, u);
                    }
                }
            }
        }
    } catch (SQLException s) {
        s.printStackTrace();
    } finally {
        try {
            rs.close();
        } catch (Exception s) {
        }
        try {
            stmt.close();
        } catch (Exception s) {
        }
        try {
            con.close();
        } catch (Exception e) {
        }

    }

}

From source file:org.wso2.carbon.is.migration.service.v510.migrator.IdentityDataMigrator.java

/**
 * migrate data in the identity database and finalize the database table restructuring
 *///from w w w. j  a v a 2  s  . c om
public void migrateIdentityData() throws MigrationClientException {
    log.info("MIGRATION-LOGS >> Going to start : migrateIdentityData.");
    Connection identityConnection = null;
    PreparedStatement selectFromAccessTokenPS = null;
    PreparedStatement insertScopeAssociationPS = null;
    PreparedStatement insertTokenScopeHashPS = null;
    PreparedStatement insertTokenIdPS = null;
    PreparedStatement updateUserNamePS = null;
    PreparedStatement selectFromAuthorizationCodePS = null;
    PreparedStatement updateUserNameAuthorizationCodePS = null;
    PreparedStatement selectIdnAssociatedIdPS = null;
    PreparedStatement updateIdnAssociatedIdPS = null;
    PreparedStatement selectConsumerAppsPS = null;
    PreparedStatement updateConsumerAppsPS = null;

    ResultSet accessTokenRS = null;
    ResultSet authzCodeRS = null;
    ResultSet selectIdnAssociatedIdRS = null;
    ResultSet selectConsumerAppsRS = null;
    try {
        identityConnection = getDataSource().getConnection();
        identityConnection.setAutoCommit(false);

        try {
            selectConsumerAppsPS = identityConnection.prepareStatement(SQLQueries.SELECT_FROM_CONSUMER_APPS);
            updateConsumerAppsPS = identityConnection.prepareStatement(SQLQueries.UPDATE_CONSUMER_APPS);

            selectConsumerAppsRS = selectConsumerAppsPS.executeQuery();
            log.info("MIGRATION-LOGS >> Executed query : " + selectConsumerAppsPS.toString());
            boolean isConsumerAppsAvail = false;
            while (selectConsumerAppsRS.next()) {
                int id = selectConsumerAppsRS.getInt("ID");
                String username = selectConsumerAppsRS.getString("USERNAME");
                String userDomainFromDB = selectConsumerAppsRS.getString("USER_DOMAIN");

                try {
                    if (userDomainFromDB == null) {
                        String userDomain = UserCoreUtil.extractDomainFromName(username);
                        username = UserCoreUtil.removeDomainFromName(username);

                        updateConsumerAppsPS.setString(1, username);
                        updateConsumerAppsPS.setString(2, userDomain);
                        updateConsumerAppsPS.setInt(3, id);
                        if (isBatchUpdate()) {
                            isConsumerAppsAvail = true;
                            updateConsumerAppsPS.addBatch();
                        } else {
                            updateConsumerAppsPS.executeUpdate();
                            log.info("MIGRATION-LOGS >> Executed query : " + updateConsumerAppsPS.toString());
                        }
                        if (log.isDebugEnabled()) {
                            log.debug("MIGRATION-LOGS >> migrating consumer app :" + id);
                        }
                    }
                } catch (Exception e) {
                    log.error("MIGRATION-ERROR-LOGS-011 >> Error while executing the migration.", e);
                    if (!isContinueOnError()) {
                        throw new MigrationClientException("Error while executing the migration.", e);
                    }
                }
            }
            if (isConsumerAppsAvail && isBatchUpdate()) {
                int[] ints = updateConsumerAppsPS.executeBatch();
                log.info("MIGRATION-LOGS >> Executed query : " + updateConsumerAppsPS.toString());
            }
        } catch (Exception e) {
            log.error("MIGRATION-ERROR-LOGS-012 >> Error while executing the migration.", e);
            if (!isContinueOnError()) {
                throw new MigrationClientException("Error while executing the migration.", e);
            }
        }

        String selectFromAccessToken = SQLQueries.SELECT_FROM_ACCESS_TOKEN;
        selectFromAccessTokenPS = identityConnection.prepareStatement(selectFromAccessToken);

        String insertScopeAssociation = SQLQueries.INSERT_SCOPE_ASSOCIATION;
        insertScopeAssociationPS = identityConnection.prepareStatement(insertScopeAssociation);

        String insertTokenScopeHash = SQLQueries.INSERT_TOKEN_SCOPE_HASH;
        insertTokenScopeHashPS = identityConnection.prepareStatement(insertTokenScopeHash);

        String insertTokenId = SQLQueries.INSERT_TOKEN_ID;
        insertTokenIdPS = identityConnection.prepareStatement(insertTokenId);

        String updateUserName = SQLQueries.UPDATE_USER_NAME;
        updateUserNamePS = identityConnection.prepareStatement(updateUserName);

        try {
            accessTokenRS = selectFromAccessTokenPS.executeQuery();
            log.info("MIGRATION-LOGS >> Executed query : " + selectFromAccessTokenPS.toString());
            while (accessTokenRS.next()) {
                String accessToken = null;
                try {
                    accessToken = accessTokenRS.getString("ACCESS_TOKEN");
                    String scopeString = accessTokenRS.getString("TOKEN_SCOPE");
                    String authzUser = accessTokenRS.getString("AUTHZ_USER");
                    String tokenIdFromDB = accessTokenRS.getString("TOKEN_ID");

                    if (tokenIdFromDB == null) {
                        String tokenId = UUID.randomUUID().toString();

                        String username = UserCoreUtil
                                .removeDomainFromName(MultitenantUtils.getTenantAwareUsername(authzUser));
                        String userDomain = UserCoreUtil.extractDomainFromName(authzUser);
                        int tenantId = ISMigrationServiceDataHolder.getRealmService().getTenantManager()
                                .getTenantId(MultitenantUtils.getTenantDomain(authzUser));

                        try {
                            insertTokenIdPS.setString(1, tokenId);
                            insertTokenIdPS.setString(2, accessToken);

                            if (isBatchUpdate()) {
                                insertTokenIdPS.addBatch();
                            } else {
                                insertTokenIdPS.executeUpdate();
                                log.info("MIGRATION-LOGS >> Executed query : " + insertTokenIdPS.toString());
                            }
                        } catch (Exception e) {
                            log.error("MIGRATION-ERROR-LOGS-013 >> Error while executing the migration.", e);
                            if (!isContinueOnError()) {
                                throw new MigrationClientException("Error while executing the migration.", e);
                            }
                        }

                        try {
                            updateUserNamePS.setString(1, username);
                            updateUserNamePS.setInt(2, tenantId);
                            updateUserNamePS.setString(3, userDomain);
                            updateUserNamePS.setString(4, authzUser);
                            updateUserNamePS.setString(5, accessToken);
                            if (isBatchUpdate()) {
                                updateUserNamePS.addBatch();
                            } else {
                                updateConsumerAppsPS.executeUpdate();
                                log.info("MIGRATION-LOGS >> Executed query : "
                                        + updateConsumerAppsPS.toString());
                            }
                        } catch (Exception e) {
                            log.error("MIGRATION-ERROR-LOGS-014 >> Error while executing the migration.", e);
                            if (!isContinueOnError()) {
                                throw new MigrationClientException("Error while executing the migration.", e);
                            }
                        }

                        try {
                            insertTokenScopeHashPS.setString(1, DigestUtils.md5Hex(scopeString));
                            insertTokenScopeHashPS.setString(2, accessToken);
                            if (isBatchUpdate()) {
                                insertTokenScopeHashPS.addBatch();
                            } else {
                                insertTokenScopeHashPS.executeUpdate();
                                log.info("MIGRATION-LOGS >> Executed query : "
                                        + insertTokenScopeHashPS.toString());
                            }
                        } catch (Exception e) {
                            log.error("MIGRATION-ERROR-LOGS-015 >> Error while executing the migration.", e);
                            if (!isContinueOnError()) {
                                throw new MigrationClientException("Error while executing the migration.", e);
                            }
                        }

                        if (log.isDebugEnabled()) {
                            log.debug("MIGRATION-LOGS >> migrating access token : " + accessToken);
                        }

                        if (scopeString != null) {
                            String scopes[] = scopeString.split(" ");
                            for (String scope : scopes) {
                                try {
                                    insertScopeAssociationPS.setString(1, tokenId);
                                    insertScopeAssociationPS.setString(2, scope);
                                    if (isBatchUpdate()) {
                                        insertScopeAssociationPS.addBatch();
                                    } else {
                                        insertScopeAssociationPS.executeUpdate();
                                        log.info("MIGRATION-LOGS >> Executed query : "
                                                + insertScopeAssociationPS.toString());
                                    }
                                } catch (Exception e) {
                                    log.error(
                                            "MIGRATION-ERROR-LOGS-016 >> Error while executing the migration.",
                                            e);
                                    if (!isContinueOnError()) {
                                        throw new MigrationClientException(
                                                "Error while executing the migration.", e);
                                    }
                                }
                            }
                        }
                    }
                } catch (UserStoreException e) {
                    log.error("MIGRATION-ERROR-LOGS-017 >> Error while executing the migration.", e);
                    if (!isContinueOnError()) {
                        throw new MigrationClientException("Error while executing the migration.", e);
                    }
                }
            }
            if (isBatchUpdate()) {
                try {
                    insertTokenIdPS.executeBatch();
                    log.info("MIGRATION-LOGS >> Executed query : " + insertTokenIdPS.toString());
                } catch (SQLException e) {
                    log.error("MIGRATION-ERROR-LOGS-018 >> Error while executing the migration.", e);
                    if (!isContinueOnError()) {
                        throw new MigrationClientException("Error while executing the migration.", e);
                    }
                }

                try {
                    log.info("MIGRATION-LOGS >> Started : " + insertScopeAssociationPS.toString());
                    insertScopeAssociationPS.executeBatch();
                    log.info("MIGRATION-LOGS >> Executed query : " + insertScopeAssociationPS.toString());
                } catch (SQLException e) {
                    log.error("MIGRATION-ERROR-LOGS-019 >> Error while executing the migration.", e);
                    if (!isContinueOnError()) {
                        throw new MigrationClientException("Error while executing the migration.", e);
                    }
                }
                try {
                    updateUserNamePS.executeBatch();
                    log.info("MIGRATION-LOGS >> Executed query : " + updateUserNamePS.toString());
                } catch (SQLException e) {
                    log.error("MIGRATION-ERROR-LOGS-020 >> Error while executing the migration.", e);
                    if (!isContinueOnError()) {
                        throw new MigrationClientException("Error while executing the migration.", e);
                    }
                }

                try {
                    insertTokenScopeHashPS.executeBatch();
                    log.info("MIGRATION-LOGS >> Executed query : " + insertTokenScopeHashPS.toString());
                } catch (SQLException e) {
                    log.error("MIGRATION-ERROR-LOGS-021 >> Error while executing the migration.", e);
                    if (!isContinueOnError()) {
                        throw new MigrationClientException("Error while executing the migration.", e);
                    }
                }
            }
        } catch (Exception e) {
            log.error("MIGRATION-ERROR-LOGS-022 >> Error while executing the migration.", e);
            if (!isContinueOnError()) {
                throw new MigrationClientException("Error while executing the migration.", e);
            }
        }

        String selectFromAuthorizationCode = SQLQueries.SELECT_FROM_AUTHORIZATION_CODE;
        selectFromAuthorizationCodePS = identityConnection.prepareStatement(selectFromAuthorizationCode);

        String updateUserNameAuthorizationCode = SQLQueries.UPDATE_USER_NAME_AUTHORIZATION_CODE;
        updateUserNameAuthorizationCodePS = identityConnection
                .prepareStatement(updateUserNameAuthorizationCode);

        try {
            authzCodeRS = selectFromAuthorizationCodePS.executeQuery();
            log.info("MIGRATION-LOGS >> Executed query : " + authzCodeRS.toString());
            while (authzCodeRS.next()) {
                String authorizationCode = null;
                try {
                    authorizationCode = authzCodeRS.getString("AUTHORIZATION_CODE");
                    String authzUser = authzCodeRS.getString("AUTHZ_USER");
                    String userDomainFromDB = authzCodeRS.getString("USER_DOMAIN");

                    if (userDomainFromDB == null) {
                        String username = UserCoreUtil
                                .removeDomainFromName(MultitenantUtils.getTenantAwareUsername(authzUser));
                        String userDomain = UserCoreUtil.extractDomainFromName(authzUser);
                        int tenantId = ISMigrationServiceDataHolder.getRealmService().getTenantManager()
                                .getTenantId(MultitenantUtils.getTenantDomain(authzUser));

                        try {
                            updateUserNameAuthorizationCodePS.setString(1, username);
                            updateUserNameAuthorizationCodePS.setInt(2, tenantId);
                            updateUserNameAuthorizationCodePS.setString(3, userDomain);
                            updateUserNameAuthorizationCodePS.setString(4, UUID.randomUUID().toString());
                            updateUserNameAuthorizationCodePS.setString(5, authzUser);
                            updateUserNameAuthorizationCodePS.setString(6, authorizationCode);
                            if (isBatchUpdate()) {
                                updateUserNameAuthorizationCodePS.addBatch();
                            } else {
                                updateUserNameAuthorizationCodePS.executeUpdate();
                                log.info("MIGRATION-LOGS >> Executed query : "
                                        + updateUserNameAuthorizationCodePS.toString());
                            }
                        } catch (Exception e) {
                            log.error("MIGRATION-ERROR-LOGS-023 >> Error while executing the migration.", e);
                            if (!isContinueOnError()) {
                                throw new MigrationClientException("Error while executing the migration.", e);
                            }
                        }
                        if (log.isDebugEnabled()) {
                            log.debug("MIGRATION-LOGS >> migrating authorization code : " + authorizationCode);
                        }
                    }
                } catch (UserStoreException e) {
                    log.warn("MIGRATION-LOGS >> Error while migrating authorization code : "
                            + authorizationCode);
                    if (!isContinueOnError()) {
                        throw new MigrationClientException("Error while executing the migration.", e);
                    }
                }
            }
            if (isBatchUpdate()) {
                updateUserNameAuthorizationCodePS.executeBatch();
                log.info("MIGRATION-LOGS >> Executed query : " + updateUserNameAuthorizationCodePS.toString());
            }
        } catch (Exception e) {
            log.error("MIGRATION-ERROR-LOGS-024 >> Error while executing the migration.", e);
            if (!isContinueOnError()) {
                throw new MigrationClientException("Error while executing the migration.", e);
            }
        }

        String selectIdnAssociatedId = SQLQueries.SELECT_IDN_ASSOCIATED_ID;
        selectIdnAssociatedIdPS = identityConnection.prepareStatement(selectIdnAssociatedId);

        try {
            selectIdnAssociatedIdRS = selectIdnAssociatedIdPS.executeQuery();

            updateIdnAssociatedIdPS = identityConnection.prepareStatement(SQLQueries.UPDATE_IDN_ASSOCIATED_ID);

            while (selectIdnAssociatedIdRS.next()) {
                int id = selectIdnAssociatedIdRS.getInt("ID");
                String username = selectIdnAssociatedIdRS.getString("USER_NAME");
                String userDomainFromDB = selectIdnAssociatedIdRS.getString("DOMAIN_NAME");

                if (userDomainFromDB == null) {
                    try {
                        updateIdnAssociatedIdPS.setString(1, UserCoreUtil.extractDomainFromName(username));
                        updateIdnAssociatedIdPS.setString(2, UserCoreUtil.removeDomainFromName(username));
                        updateIdnAssociatedIdPS.setInt(3, id);
                        if (isBatchUpdate()) {
                            updateIdnAssociatedIdPS.addBatch();
                        } else {
                            updateIdnAssociatedIdPS.executeUpdate();
                            log.info(
                                    "MIGRATION-LOGS >> Executed query : " + updateIdnAssociatedIdPS.toString());
                        }
                        if (log.isDebugEnabled()) {
                            log.debug("MIGRATION-LOGS >> migrating IdnAssociatedId : " + id);
                        }
                    } catch (Exception e) {
                        log.error("MIGRATION-ERROR-LOGS-024 >> Error while executing the migration.", e);
                        if (!isContinueOnError()) {
                            throw new MigrationClientException("Error while executing the migration.", e);
                        }
                    }
                }
            }
            if (isBatchUpdate()) {
                updateIdnAssociatedIdPS.executeBatch();
                log.info("MIGRATION-LOGS >> Executed query : " + updateIdnAssociatedIdPS.toString());
            }
        } catch (Exception e) {
            log.error("MIGRATION-ERROR-LOGS-025 >> Error while executing the migration.", e);
            if (!isContinueOnError()) {
                throw new MigrationClientException("Error while executing the migration.", e);
            }
        }

        identityConnection.commit();

    } catch (SQLException e) {
        IdentityDatabaseUtil.rollBack(identityConnection);
        log.error("MIGRATION-ERROR-LOGS--026 >> Error while executing the migration.", e);
        if (!isContinueOnError()) {
            throw new MigrationClientException("Error while executing the migration.", e);
        }
    } catch (Exception e) {
        log.error("MIGRATION-ERROR-LOGS-027 >> Error while executing the migration.", e);
        if (!isContinueOnError()) {
            throw new MigrationClientException("Error while executing the migration.", e);
        }
    } finally {
        try {
            IdentityDatabaseUtil.closeResultSet(accessTokenRS);
            IdentityDatabaseUtil.closeResultSet(authzCodeRS);
            IdentityDatabaseUtil.closeResultSet(selectIdnAssociatedIdRS);
            IdentityDatabaseUtil.closeResultSet(selectConsumerAppsRS);

            IdentityDatabaseUtil.closeStatement(selectFromAccessTokenPS);
            IdentityDatabaseUtil.closeStatement(insertScopeAssociationPS);
            IdentityDatabaseUtil.closeStatement(insertTokenIdPS);
            IdentityDatabaseUtil.closeStatement(updateUserNamePS);
            IdentityDatabaseUtil.closeStatement(insertTokenScopeHashPS);
            IdentityDatabaseUtil.closeStatement(updateUserNameAuthorizationCodePS);
            IdentityDatabaseUtil.closeStatement(selectFromAuthorizationCodePS);
            IdentityDatabaseUtil.closeStatement(selectIdnAssociatedIdPS);
            IdentityDatabaseUtil.closeStatement(updateIdnAssociatedIdPS);
            IdentityDatabaseUtil.closeStatement(selectConsumerAppsPS);
            IdentityDatabaseUtil.closeStatement(updateConsumerAppsPS);

            IdentityDatabaseUtil.closeConnection(identityConnection);
        } catch (Exception e) {
            log.error("MIGRATION-ERROR-LOGS-028 >> Error while executing the migration.", e);
        }
    }
    log.info("MIGRATION-LOGS >> Done : migrateIdentityData.");
}