Example usage for java.sql ResultSet equals

List of usage examples for java.sql ResultSet equals

Introduction

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

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:adapter.gbase.signalling.SignallingAdapter.java

/**
 * ???//w w  w .  j  a va 2s. c om
 * @author LeiYun
 * 2015924
 * @return
 * @throws Exception
 */
private List<DictionaryEntity> getStatus() throws Exception {
    List<DictionaryEntity> dictionaryList = new ArrayList<DictionaryEntity>();
    Statement statement = null;
    ResultSet resultSet = null;
    try {

        statement = DbKit.getConfig("gbase").getConnection().createStatement();
        String sql = "select status,status_code from ads_dia_http_status";
        resultSet = statement.executeQuery(sql);
        while (resultSet.next()) {
            DictionaryEntity dictionary = new DictionaryEntity();
            dictionary.setKey(resultSet.getString("status"));
            dictionary.setName(resultSet.getString("status_code"));
            dictionaryList.add(dictionary);
        }
    } catch (Exception ex) {
        throw ex;
    } finally {
        if (statement != null) {
            statement.close();
        }
        if (!resultSet.equals(null)) {
            resultSet.close();
        }
    }
    return dictionaryList;
}

From source file:adapter.gbase.signalling.SignallingAdapter.java

@Override
public List<DictionaryEntity> getFlowType() throws Exception {
    // TODO Auto-generated method stub

    List<DictionaryEntity> dictionaryList = new ArrayList<DictionaryEntity>();
    Statement statement = null;// www.ja v  a  2s.c  o  m
    ResultSet resultSet = null;
    try {

        statement = DbKit.getConfig("gbase").getConnection().createStatement();
        String sql = " SELECT `procedure_type_code`,`procedure_type`,`proto_type_code`,`proto_type`,`event_type_code`,`event_type`,`interface_id`,`interface_name` FROM `dw`.`ads_dia_pro_evnet_map`";
        resultSet = statement.executeQuery(sql);
        while (resultSet.next()) {
            DictionaryEntity dictionary = new DictionaryEntity();
            dictionary.setKey(resultSet.getString("procedure_type_code"));
            dictionary.setName(resultSet.getString("procedure_type"));
            dictionary.setProp1key(resultSet.getString("proto_type_code"));
            dictionary.setProp1Name(resultSet.getString("proto_type"));
            dictionary.setProp2key(resultSet.getString("interface_id"));
            dictionary.setProp2Name(resultSet.getString("interface_name"));
            dictionaryList.add(dictionary);
        }
    } catch (Exception ex) {
        throw ex;
    } finally {
        if (statement != null) {
            statement.close();
        }
        if (!resultSet.equals(null)) {
            resultSet.close();
        }
    }
    return dictionaryList;
}

From source file:adapter.gbase.signalling.SignallingAdapter.java

@Override
public SignallingDetailEntity getSignallingDetail(String tabName, String startDate, String endDate,
        String phone, String xdrId, String rowKey) throws Exception {
    SignallingDetailEntity signallingDetail = new SignallingDetailEntity();
    Statement statement = null;/*from  w  w w.  ja v a  2s.co  m*/
    ResultSet resultSet = null;
    try {
        statement = DbKit.getConfig("gbase").getConnection().createStatement();
        String sql = "";
        if (tabName.equals("gn")) {
            sql = "SELECT `xdr_id`,`imsi`,`msisdn`,`imei`,`imei_tac`,`tac`,`eci`,`sgw_ip`,`sgw_port`,`apn`,`start_time`,`end_time`,`time_hour`,`time_day`,`protocol`,`app_type`,`app_subtype`,`app_content`,`app_status`,`user_ip`,`user_ip_type`,`user_port`,`l4_protocol`,`appserver_ip`,`appserver_ip_type`,`appserver_port`,`ulthroughput`,`dlthroughput`,`ulpackets`,`dlpackets`,`ultcp_disorder_packets`,`dltcp_disorder_packets`,`ultcp_retransfer_packets`,`dltcp_retransfer_packets`,`ultcp_response_time`,`dltcp_response_time`,`ultcp_flag_packets`,`dltcp_flag_packets`,`tcplink_response_time1`,`tcplink_response_time2`,`window_size`,`mss_size`,`tcplink_count`,`tcplink_state`,`finish`,`session_duration` FROM `dw`.`f_ms_s1u_general`";
            sql += " where 2>1";
            if (startDate != null) {
                sql += " and start_time=" + startDate;
            }
            if (endDate != null) {
                sql += " and end_time=" + endDate;
            }
            if (xdrId != "" && xdrId != null) {
                sql += " and xdr_id='" + xdrId + "'";
            }
            if (phone != "" && phone != null) {
                sql += " and msisdn=" + phone;
            }
            sql += " limit 0,1";
        } else if (tabName.equals("http")) {
            sql = "  SELECT `xdr_id`,`imsi`,`msisdn`,`imei`,`imei_tac`,`tac`,`eci`,`sgw_ip`,`sgw_port`,`apn`,`start_time`,`end_time`,`time_hour`,`time_day`,`protocol`,`app_type`,`app_subtype`,`app_content`,`app_status`,`user_ip`,`user_ip_type`,`user_port`,`l4_protocol`,`appserver_ip`,`appserver_ip_type`,`appserver_port`,`ulthroughput`,`dlthroughput`,`ulpackets`,`dlpackets`,`ultcp_disorder_packets`,`dltcp_disorder_packets`,`ultcp_retransfer_packets`,`dltcp_retransfer_packets`,`ultcp_response_time`,`dltcp_response_time`,`ultcp_flag_packets`,`dltcp_flag_packets`,`tcplink_response_time1`,`tcplink_response_time2`,`window_size`,`mss_size`,`tcplink_count`,`tcplink_state`,`finish`,`http_version`,`trans_type`,`http_status_code`,`response_time`,`lastpacket_delay`,`lastpacket_ack_delay`,`host`,`uri1`,`x_online_host`,`useragent`,`content_type`,`refer_uri`,`cookie`,`content_length`,`target_behavior`,`wtp_suspend_type`,`wtp_suspend_cause`,`title`,`keyword`,`action`,`succ_flag`,`action_delay`,`browse_tool`,`portals`,`session_duration` FROM `dw`.`f_ms_s1u_http`";
            sql += " where 2>1";
            if (startDate != null) {
                sql += " and start_time=" + startDate;
            }
            if (endDate != null) {
                sql += " and end_time=" + endDate;
            }
            if (xdrId != "" && xdrId != null) {
                sql += " and xdr_id='" + xdrId + "'";
            }
            if (phone != "" && phone != null) {
                sql += " and msisdn=" + phone;
            }
            sql += " limit 0,1";
        } else if (tabName.equals("dns")) {
            sql = "SELECT `xdr_id`,`imsi`,`msisdn`,`imei`,`imei_tac`,`tac`,`eci`,`sgw_ip`,`sgw_port`,`apn`,`start_time`,`end_time`,`time_hour`,`time_day`,`protocol`,`app_type`,`app_subtype`,`app_content`,`app_status`,`user_ip`,`user_ip_type`,`user_port`,`l4_protocol`,`appserver_ip`,`appserver_ip_type`,`appserver_port`,`ulthroughput`,`dlthroughput`,`ulpackets`,`dlpackets`,`ultcp_disorder_packets`,`dltcp_disorder_packets`,`ultcp_retransfer_packets`,`dltcp_retransfer_packets`,`ultcp_response_time`,`dltcp_response_time`,`ultcp_flag_packets`,`dltcp_flag_packets`,`tcplink_response_time1`,`tcplink_response_time2`,`window_size`,`mss_size`,`tcplink_count`,`tcplink_state`,`finish`,`domain`,`query_result_ip`,`dns_reply_code`,`dns_request_count`,`dns_response_count`,`dns_licensed_content`,`dns_add_content`,`session_duration` FROM `dw`.`f_ms_s1u_dns`";
            sql += " where 2>1";
            if (startDate != null) {
                sql += " and start_time=" + startDate;
            }
            if (endDate != null) {
                sql += " and end_time=" + endDate;
            }
            if (xdrId != "" && xdrId != null) {
                sql += " and xdr_id='" + xdrId + "'";
            }
            if (phone != "" && phone != null) {
                sql += " and msisdn=" + phone;
            }
            sql += " limit 0,1";
        } else if (tabName.equals("im")) {
            sql = "SELECT `xdr_id`,`imsi`,`msisdn`,`imei`,`imei_tac`,`tac`,`eci`,`sgw_ip`,`sgw_port`,`apn`,`start_time`,`end_time`,`time_hour`,`time_day`,`protocol`,`app_type`,`app_subtype`,`app_content`,`app_status`,`user_ip`,`user_ip_type`,`user_port`,`l4_protocol`,`appserver_ip`,`appserver_ip_type`,`appserver_port`,`ulthroughput`,`dlthroughput`,`ulpackets`,`dlpackets`,`ultcp_disorder_packets`,`dltcp_disorder_packets`,`ultcp_retransfer_packets`,`dltcp_retransfer_packets`,`ultcp_response_time`,`dltcp_response_time`,`ultcp_flag_packets`,`dltcp_flag_packets`,`tcplink_response_time1`,`tcplink_response_time2`,`window_size`,`mss_size`,`tcplink_count`,`tcplink_state`,`finish`,`username`,`version`,`client_type`,`content_type`,`session_duration` FROM `dw`.`f_ms_s1u_im`";
            sql += " where 2>1";
            if (startDate != null) {
                sql += " and start_time=" + startDate;
            }
            if (endDate != null) {
                sql += " and end_time=" + endDate;
            }
            if (xdrId != "" && xdrId != null) {
                sql += " and xdr_id='" + xdrId + "'";
            }
            if (phone != "" && phone != null) {
                sql += " and msisdn=" + phone;
            }
            sql += " limit 0,1";
        } else if (tabName.equals("mme")) {
            sql = "SELECT `xdr_id`,`imsi`,`msisdn`,`imei`,`imei_tac`,`tac`,`eci`,`other_tac`,`other_eci`,`apn`,`mme_ip`,`mme_port`,`start_time`,`end_time`,`time_hour`,`time_day`,`procedure_type`,`procedure_status`,`request_cause`,`failure_cause`,`eps_bearer_number`,`bearer_1_id`,`bearer_1_type`,`bearer_1_qci`,`bearer_1_status`,`bearer_1_request_cause`,`bearer_1_failure_cause`,`bearer_1_enb_gtp_teid`,`bearer_1_sgw_gtp_teid`,`bearer_2_id`,`bearer_2_type`,`bearer_2_qci`,`bearer_2_status`,`bearer_2_request_cause`,`bearer_2_failure_cause`,`bearer_2_enb_gtp_teid`,`bearer_2_sgw_gtp_teid`,`session_duration` FROM `dw`.`f_ms_s1mme`";
            sql += " where 2>1";
            if (startDate != null) {
                sql += " and start_time=" + startDate;
            }
            if (endDate != null) {
                sql += " and end_time=" + endDate;
            }
            if (xdrId != "" && xdrId != null) {
                sql += " and xdr_id='" + xdrId + "'";
            }
            if (phone != "" && phone != null) {
                sql += " and msisdn=" + phone;
            }
            sql += " limit 0,1";
        }

        System.out.println(sql);
        resultSet = statement.executeQuery(sql);

        String cols = "";
        JSONArray array = new JSONArray();
        ResultSetMetaData metaData = resultSet.getMetaData();
        int columnCount = metaData.getColumnCount();
        for (int i = 1; i <= columnCount; i++) {
            String columnName = metaData.getColumnLabel(i);
            if (!cols.equals("")) {
                cols += ",";
            }
            cols += columnName;
        }
        while (resultSet.next()) {
            JSONObject jsonObj = new JSONObject();

            for (int i = 1; i <= columnCount; i++) {
                String columnName = metaData.getColumnLabel(i);
                String value = resultSet.getString(columnName);
                jsonObj.put(columnName, value);
            }
            array.add(jsonObj);
        }
        signallingDetail.setSql(sql);
        signallingDetail.setCols(cols);
        signallingDetail.setJsonArray(array);
    } catch (Exception ex) {
        throw ex;
    } finally {
        if (statement != null) {
            statement.close();
        }
        if (!resultSet.equals(null)) {
            resultSet.close();
        }
    }

    return signallingDetail;
}

From source file:org.ensembl.healthcheck.util.DBUtils.java

public static boolean compareResultSets(ResultSet rs1, ResultSet rs2, EnsTestCase testCase, String text,
        boolean reportErrors, boolean warnNull, String singleTableName, int[] columns,
        boolean comparingSchema) {

    // quick tests first
    // Check for object equality
    if (rs1.equals(rs2)) {
        return true;
    }// w  w  w  . ja  va2  s  .c o m

    try {

        // get some information about the ResultSets
        String name1 = getShortDatabaseName(rs1.getStatement().getConnection());
        String name2 = getShortDatabaseName(rs2.getStatement().getConnection());

        // Check for same column count, names and types
        ResultSetMetaData rsmd1 = rs1.getMetaData();
        ResultSetMetaData rsmd2 = rs2.getMetaData();
        if (rsmd1.getColumnCount() != rsmd2.getColumnCount() && columns == null) {

            if (reportErrors) {

                ReportManager.problem(testCase, name1, "Column counts differ " + singleTableName + " " + name1
                        + ": " + rsmd1.getColumnCount() + " " + name2 + ": " + rsmd2.getColumnCount());
            }

            return false; // Deliberate early return for performance
            // reasons
        }

        if (columns == null) {
            columns = new int[rsmd1.getColumnCount()];
            for (int i = 0; i < columns.length; i++) {
                columns[i] = i + 1;
            }
        }

        for (int j = 0; j < columns.length; j++) {
            int i = columns[j];

            // note columns indexed from l
            if (!((rsmd1.getColumnName(i)).equals(rsmd2.getColumnName(i)))) {

                if (reportErrors) {

                    ReportManager.problem(testCase, name1,
                            "Column names differ for " + singleTableName + " column " + i + " - " + name1 + ": "
                                    + rsmd1.getColumnName(i) + " " + name2 + ": " + rsmd2.getColumnName(i));
                }

                // Deliberate early return for performance reasons
                return false;

            }
            if (rsmd1.getColumnType(i) != rsmd2.getColumnType(i)) {

                if (reportErrors) {

                    ReportManager.problem(testCase, name1,
                            "Column types differ for " + singleTableName + " column " + i + " - " + name1 + ": "
                                    + rsmd1.getColumnType(i) + " " + name2 + ": " + rsmd2.getColumnType(i));
                }
                return false; // Deliberate early return for performance
                // reasons
            }
        } // for column

        // make sure both cursors are at the start of the ResultSet
        // (default is before the start)
        rs1.beforeFirst();
        rs2.beforeFirst();
        // if quick checks didn't cause return, try comparing row-wise

        int row = 1;
        while (rs1.next()) {

            if (rs2.next()) {
                String str = name1 + " and " + name2 + text + " " + singleTableName + " with columns ";
                for (int j = 0; j < columns.length; j++) {
                    int i = columns[j];
                    str += rsmd1.getColumnName(i) + " " + Utils.truncate(rs1.getString(i), 250, true) + ", ";
                    // note columns indexed from 1
                    if (!compareColumns(rs1, rs2, i, warnNull)) {
                        str += " differ for values " + Utils.truncate(rs1.getString(i), 250, true) + ", "
                                + Utils.truncate(rs2.getString(i), 250, true);
                        if (reportErrors) {
                            ReportManager.problem(testCase, name1, str);
                        }
                        return false;
                    }
                }
                row++;

            } else {
                // rs1 has more rows than rs2
                if (reportErrors) {
                    ReportManager.problem(testCase, name1,
                            singleTableName + " has more rows in " + name1 + " than in " + name2);
                }
                return false;
            }

        } // while rs1

        // if both ResultSets are the same, then we should be at the end of
        // both, i.e. .next() should return false
        String extra = comparingSchema ? ". This means that there are missing columns in the table, rectify!"
                : "";
        if (rs1.next()) {

            if (reportErrors) {
                ReportManager.problem(testCase, name1, name1 + " " + singleTableName
                        + " has additional rows that are not in " + name2 + extra);
            }
            return false;
        } else if (rs2.next()) {

            if (reportErrors) {
                ReportManager.problem(testCase, name1, name2 + " " + singleTableName
                        + " has additional rows that are not in " + name1 + extra);

            }
            return false;
        }

    } catch (SQLException se) {
        throw new SqlUncheckedException("Could not compare two result sets", se);
    }

    return true;

}

From source file:org.executequery.databaseobjects.impl.DelegatingResultSet.java

public boolean equals(Object obj) {
    ResultSet delegate = getInnermostDelegate();
    if (delegate == null) {
        return false;
    }/*from  ww  w .ja  v  a  2  s  .c  o  m*/
    if (obj instanceof DelegatingResultSet) {
        DelegatingResultSet s = (DelegatingResultSet) obj;
        return delegate.equals(s.getInnermostDelegate());
    } else {
        return delegate.equals(obj);
    }
}