Example usage for java.sql ResultSet getBoolean

List of usage examples for java.sql ResultSet getBoolean

Introduction

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

Prototype

boolean getBoolean(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a boolean in the Java programming language.

Usage

From source file:net.certifi.audittablegen.GenericDMR.java

public Map<String, DataTypeDef> getDataTypes() {

    if (this.dataTypes != null) {
        return this.dataTypes;
    }// ww  w  .  ja  va2 s  .  c  om

    //this is kind of ugly.  Some databases (postgres) return the VALUES of
    //metadata in lowercase, while others (hsqldb) return the VALUES of
    //metadata in uppercase.  This is why the key values are stored as
    //case insensitive - so it will work with default types for 
    Map<String, DataTypeDef> types = new CaseInsensitiveMap();

    try {
        Connection conn = dataSource.getConnection();
        DatabaseMetaData dmd = conn.getMetaData();
        ResultSet rs = dmd.getTypeInfo();

        if (!rs.isBeforeFirst()) {
            throw new RuntimeException("No results for DatabaseMetaData.getTypeInfo()");
        }
        while (rs.next()) {

            DataTypeDef dtd = new DataTypeDef();

            dtd.type_name = rs.getString("TYPE_NAME");
            dtd.data_type = rs.getInt("DATA_TYPE");
            dtd.precision = rs.getInt("PRECISION");
            dtd.literal_prefix = rs.getString("LITERAL_PREFIX");
            dtd.literal_suffix = rs.getString("LITERAL_SUFFIX");
            dtd.create_params = rs.getString("CREATE_PARAMS");
            dtd.nullable = rs.getShort("NULLABLE");
            dtd.case_sensitive = rs.getBoolean("CASE_SENSITIVE");
            dtd.searchable = rs.getShort("SEARCHABLE");
            dtd.unsigned_attribute = rs.getBoolean("UNSIGNED_ATTRIBUTE");
            dtd.fixed_prec_scale = rs.getBoolean("FIXED_PREC_SCALE");
            dtd.auto_increment = rs.getBoolean("AUTO_INCREMENT");
            dtd.local_type_name = rs.getString("LOCAL_TYPE_NAME");
            dtd.minimum_scale = rs.getShort("MINIMUM_SCALE");
            dtd.maximum_scale = rs.getShort("MAXIMUM_SCALE");
            dtd.sql_data_type = rs.getInt("SQL_DATA_TYPE"); //not used
            dtd.sql_datetime_sub = rs.getInt("SQL_DATETIME_SUB"); //not used
            dtd.num_prec_radix = rs.getInt("NUM_PREC_RADIX");

            //google guava primitive types tools
            if (Ints.contains(DataTypeDef.sqlSizedTypes, dtd.data_type) && !dtd.type_name.equals("text")) {
                dtd.createWithSize = true;
            }

            types.put(dtd.type_name, dtd);

        }

    } catch (SQLException e) {
        throw Throwables.propagate(e);
    }

    this.dataTypes = types;

    Collection<String> debugValues = types.keySet();
    for (String debugValue : debugValues) {
        logger.debug("DB has type value {}", debugValue);

    }

    return types;

}

From source file:com.enonic.vertical.engine.handlers.SectionHandler.java

public boolean isSectionOrdered(int sectionKey) {

    Connection con = null;//www  . ja v  a 2 s.co  m
    PreparedStatement preparedStmt = null;
    ResultSet resultSet = null;
    boolean ordered = false;

    try {
        con = getConnection();
        StringBuffer sql = XDG.generateSelectSQL(db.tMenuItem, db.tMenuItem.mei_bOrderedSection, false,
                db.tMenuItem.mei_lKey);
        preparedStmt = con.prepareStatement(sql.toString());
        preparedStmt.setInt(1, sectionKey);
        resultSet = preparedStmt.executeQuery();
        if (resultSet.next()) {
            ordered = resultSet.getBoolean(1);
        }
    } catch (SQLException sqle) {
        String message = "Failed to append section names to content: %t";
        VerticalEngineLogger.error(this.getClass(), 1, message, sqle);
    } finally {
        close(resultSet);
        close(preparedStmt);
        close(con);
    }

    return ordered;
}

From source file:com.cws.us.pws.dao.impl.ProductReferenceDAOImpl.java

/**
 * @see com.cws.us.pws.dao.interfaces.IProductReferenceDAO#getProductData(String, String) throws SQLException
 *//*w  w w  . j  ava2s.c  om*/
@Override
public List<Object> getProductData(final String productId, final String lang) throws SQLException {
    final String methodName = IProductReferenceDAO.CNAME
            + "#getProductData(final int productId, final String lang) throws SQLException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", productId);
        DEBUGGER.debug("Value: {}", lang);
    }

    Connection sqlConn = null;
    ResultSet resultSet = null;
    List<Object> results = null;
    CallableStatement stmt = null;

    try {
        sqlConn = this.dataSource.getConnection();

        if (DEBUG) {
            DEBUGGER.debug("Connection: {}", sqlConn);
        }

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain connection to application datasource");
        }

        stmt = sqlConn.prepareCall("{ CALL getProductData(?, ?) }");
        stmt.setString(1, productId);
        stmt.setString(2, lang);

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        if (!(stmt.execute())) {
            throw new SQLException("PreparedStatement is null. Cannot execute.");
        }

        resultSet = stmt.getResultSet();

        if (DEBUG) {
            DEBUGGER.debug("ResultSet: {}", resultSet);
        }

        if (resultSet.next()) {
            resultSet.beforeFirst();
            results = new ArrayList<Object>();

            while (resultSet.next()) {
                results.add(resultSet.getString(1)); // PRODUCT_ID
                results.add(resultSet.getString(2)); // PRODUCT_NAME
                results.add(resultSet.getString(3)); // PRODUCT_SHORT_DESC
                results.add(resultSet.getString(4)); // PRODUCT_DESC
                results.add(resultSet.getBigDecimal(5)); // PRODUCT_PRICE
                results.add(resultSet.getBoolean(6)); // IS_FEATURED
            }

            if (DEBUG) {
                DEBUGGER.debug("results: {}", results);
            }
        }
    } catch (SQLException sqx) {
        ERROR_RECORDER.error(sqx.getMessage(), sqx);

        throw new SQLException(sqx.getMessage(), sqx);
    } finally {
        if (resultSet != null) {
            resultSet.close();
        }

        if (stmt != null) {
            stmt.close();
        }

        if ((sqlConn != null) && (!(sqlConn.isClosed()))) {
            sqlConn.close();
        }
    }

    if (DEBUG) {
        DEBUGGER.debug("results: {}", results);
    }

    return results;
}

From source file:csiro.pidsvc.mappingstore.ManagerJson.java

@SuppressWarnings("unchecked")
protected JSONObject getPidConfigImpl(String query, Object value) throws SQLException {
    //      InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("../pid.json");
    //      byte[] bytes = new byte[inputStream.available()]; 
    //      inputStream.read(bytes); 
    //      String s = new String(bytes); 
    //      return s;

    PreparedStatement pst = null;
    ResultSet rsMapping = null, rsAction = null, rsHistory = null;
    JSONObject ret = null;//from w w  w.ja  va  2 s.co  m
    JSONArray jsonArr = null;
    int mappingId;
    String mappingPath, parentPath;
    boolean isParentActive;

    try {
        pst = _connection.prepareStatement(query);
        if (value != null) {
            if (value instanceof Integer)
                pst.setInt(1, (Integer) value);
            else
                pst.setString(1, (String) value);
        }

        if (pst.execute()) {
            ret = new JSONObject();
            for (rsMapping = pst.getResultSet(); rsMapping.next();) {
                String actionType = rsMapping.getString("action_type");
                if (rsMapping.wasNull())
                    actionType = null;

                mappingId = rsMapping.getInt("mapping_id");
                mappingPath = rsMapping.getString("mapping_path");
                parentPath = rsMapping.getString("parent");
                isParentActive = rsMapping.getBoolean("parent_is_active");

                ret.put("mapping_id", mappingId);
                ret.put("mapping_path", mappingPath);
                ret.put("original_path", rsMapping.getString("original_path"));
                ret.put("type", mappingPath == null ? "Regex" : rsMapping.getString("type"));
                ret.put("title", mappingPath == null ? "Catch-all" : rsMapping.getString("title"));
                ret.put("description", rsMapping.getString("description"));
                ret.put("creator", rsMapping.getString("creator"));
                ret.put("commit_note", rsMapping.getString("commit_note"));
                ret.put("ended", rsMapping.getBoolean("ended"));
                ret.put("qr_hits", this.getTotalQrCodeHits(mappingPath));

                // Parent mapping.
                JSONObject jsonParent = new JSONObject();
                jsonParent.put("mapping_path", parentPath);
                jsonParent.put("title", rsMapping.getString("parent_title"));
                jsonParent.put("active", isParentActive);
                if (isParentActive)
                    jsonParent.put("cyclic", !this.checkNonCyclicInheritance(mappingId));
                jsonParent.put("graph", getMappingDependencies(mappingId, parentPath));
                ret.put("parent", jsonParent);

                // Default action.
                if (actionType == null)
                    ret.put("action", null);
                else {
                    ret.put("action", JSONObjectHelper.create("type", actionType, "name",
                            rsMapping.getString("action_name"), "value", rsMapping.getString("action_value"),
                            "description", rsMapping.getString("default_action_description")));
                }

                // Serialise change history.
                pst = _connection.prepareStatement("SELECT mapping_id, creator, commit_note, "
                        + "   to_char(date_start, 'DD/MM/YYYY HH24:MI') AS date_start, "
                        + "   to_char(date_end, 'DD/MM/YYYY HH24:MI') AS date_end " + "FROM mapping "
                        + "WHERE mapping_path " + (mappingPath == null ? "IS NULL " : "= ? ")
                        + "ORDER BY mapping.date_start DESC");
                if (mappingPath != null)
                    pst.setString(1, mappingPath);

                // History.
                jsonArr = new JSONArray();
                if (pst.execute()) {
                    for (rsHistory = pst.getResultSet(); rsHistory.next();) {
                        jsonArr.add(JSONObjectHelper.create("mapping_id", rsHistory.getInt("mapping_id"),
                                "creator", rsHistory.getString("creator"), "commit_note",
                                rsHistory.getString("commit_note"), "date_start",
                                rsHistory.getString("date_start"), "date_end",
                                rsHistory.getString("date_end")));
                    }
                }
                ret.put("history", jsonArr);

                // Conditions.
                ret.put("conditions", getConditionsByMappingId(rsMapping.getInt("mapping_id")));
            }

            if (value == null && (ret == null || ret.isEmpty())) {
                // Catch-all mapping is not defined yet. Return default.
                ret = JSONObjectHelper.create(
                        "mapping_id", 0, "mapping_path", null, "original_path", null, "type", "Regex", "title",
                        "Catch-all", "description", null, "creator", null, "commit_note", null, "ended", false,
                        "qr_hits", 0, "parent", null, "action", JSONObjectHelper.create("type", "404", "name",
                                null, "value", null, "description", null),
                        "history", null, "conditions", new JSONArray());
            }
        }
    } finally {
        if (rsMapping != null)
            rsMapping.close();
        if (rsAction != null)
            rsAction.close();
        if (rsHistory != null)
            rsHistory.close();
        if (pst != null)
            pst.close();
    }
    return ret;
}

From source file:com.cws.esolutions.core.dao.impl.WebMessagingDAOImpl.java

/**
 * @see com.cws.esolutions.core.dao.interfaces.IWebMessagingDAO#retrieveAlertMessages()
 *///from  ww w  .  j  a v a 2 s.com
public synchronized List<Object[]> retrieveAlertMessages() throws SQLException {
    final String methodName = IWebMessagingDAO.CNAME + "#retrieveAlertMessages() throws SQLException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
    }

    Connection sqlConn = null;
    ResultSet resultSet = null;
    CallableStatement stmt = null;
    List<Object[]> response = null;

    try {
        sqlConn = dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);
        stmt = sqlConn.prepareCall("{CALL retrAlertMessages()}");

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        if (stmt.execute()) {
            resultSet = stmt.getResultSet();

            if (DEBUG) {
                DEBUGGER.debug("ResultSet: {}", resultSet);
            }

            if (resultSet.next()) {
                resultSet.beforeFirst();
                response = new ArrayList<Object[]>();

                while (resultSet.next()) {
                    Object[] data = new Object[] { resultSet.getString(1), // svc_message_id
                            resultSet.getString(2), // svc_message_title
                            resultSet.getString(3), // svc_message_txt
                            resultSet.getString(4), // svc_message_author
                            resultSet.getTimestamp(5), // svc_message_submitdate
                            resultSet.getBoolean(6), // svc_message_active
                            resultSet.getBoolean(7), // svc_message_alert
                            resultSet.getBoolean(8), // svc_message_expires
                            resultSet.getTimestamp(9), // svc_message_expirydate
                            resultSet.getTimestamp(10), // svc_message_modifiedon
                            resultSet.getString(11) // svc_message_modifiedby
                    };

                    if (DEBUG) {
                        DEBUGGER.debug("data: {}", data);
                    }

                    response.add(data);
                }
            }
        }
    } catch (SQLException sqx) {
        ERROR_RECORDER.error(sqx.getMessage(), sqx);

        throw new SQLException(sqx.getMessage(), sqx);
    } finally {
        if (resultSet != null) {
            resultSet.close();
        }

        if (stmt != null) {
            stmt.close();
        }

        if ((sqlConn != null) && (!(sqlConn.isClosed()))) {
            sqlConn.close();
        }
    }

    return response;
}

From source file:com.sfs.whichdoctor.dao.AssessmentDAOImpl.java

/**
 * Load assessment bean.//from w w  w.  j  a  v a  2 s.c o  m
 *
 * @param rs the rs
 * @param loadDetails the load details
 * @return the assessment bean
 * @throws SQLException the sQL exception
 */
private AssessmentBean loadAssessmentBean(final ResultSet rs, final BuilderBean loadDetails)
        throws SQLException {

    AssessmentBean assessment = new AssessmentBean();

    /* Create resource bean and fill with dataset info */
    assessment.setId(rs.getInt("AssessmentId"));
    assessment.setGUID(rs.getInt("GUID"));
    assessment.setAssessmentType(rs.getString("AssessmentType"));

    /* Set assessment details */
    assessment.setTrainingOrganisation(rs.getString("TrainingOrganisation"));
    assessment.setTrainingProgram(rs.getString("TrainingProgram"));
    assessment.setTrainingProgramISBMapping(rs.getString("TrainingProgramISBMapping"));
    assessment.setCommitteeSpecialty(rs.getString("SpecialtyType"));
    assessment.setCommitteeSpecialtyAbbreviation(rs.getString("SpecialtyTypeAbbreviation"));
    assessment.setYearOfTraining(rs.getInt("YearOfTraining"));

    assessment.setStatus(rs.getString("FeedbackStatus"));
    assessment.setStatusReason(rs.getString("StatusReason"));
    assessment.setApproved(rs.getString("Approved"));
    assessment.setApprovedCondition(rs.getString("ApprovedCondition"));
    assessment.setApplicationComment(rs.getString("ApplicationComment"));
    assessment.setAccreditationComment(rs.getString("AccreditationComment"));

    RotationBean rotation = new RotationBean();
    rotation.setGUID(rs.getInt("ReferenceGUID"));
    assessment.setRotation(rotation);

    assessment.setActive(rs.getBoolean("Active"));
    if (loadDetails.getBoolean("HISTORY")) {
        try {
            assessment.setCreatedDate(rs.getTimestamp("CreatedDate"));
        } catch (SQLException sqe) {
            dataLogger.debug("Error parsing ModifiedDate: " + sqe.getMessage());
        }
        assessment.setCreatedBy(rs.getString("CreatedBy"));
        try {
            assessment.setModifiedDate(rs.getTimestamp("ModifiedDate"));
        } catch (SQLException sqe) {
            dataLogger.debug("Error parsing ModifiedDate: " + sqe.getMessage());
        }
        assessment.setModifiedBy(rs.getString("ModifiedBy"));
    }

    /* Load user details */
    if (loadDetails.getBoolean("CREATED")) {
        try {
            UserBean user = new UserBean();
            user.setDN(rs.getString("CreatedBy"));
            user.setPreferredName(rs.getString("CreatedFirstName"));
            user.setLastName(rs.getString("CreatedLastName"));
            assessment.setCreatedUser(user);
        } catch (SQLException sqe) {
            dataLogger.debug("Error loading created user details: " + sqe.getMessage());
        }
    }
    if (loadDetails.getBoolean("MODIFIED")) {
        try {
            UserBean user = new UserBean();
            user.setDN(rs.getString("ModifiedBy"));
            user.setPreferredName(rs.getString("ModifiedFirstName"));
            user.setLastName(rs.getString("ModifiedLastName"));
            assessment.setModifiedUser(user);
        } catch (SQLException sqe) {
            dataLogger.debug("Error loading modified user details: " + sqe.getMessage());
        }
    }

    return assessment;
}

From source file:com.cws.esolutions.core.dao.impl.WebMessagingDAOImpl.java

/**
 * @see com.cws.esolutions.core.dao.interfaces.IWebMessagingDAO#retrieveMessages()
 */// w w w.  jav a  2 s  .  c  om
public synchronized List<Object[]> retrieveMessages() throws SQLException {
    final String methodName = IWebMessagingDAO.CNAME + "#retrieveMessages() throws SQLException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
    }

    Connection sqlConn = null;
    ResultSet resultSet = null;
    CallableStatement stmt = null;
    List<Object[]> response = null;

    try {
        sqlConn = dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);
        stmt = sqlConn.prepareCall("{CALL retrServiceMessages()}");

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        if (stmt.execute()) {
            resultSet = stmt.getResultSet();

            if (DEBUG) {
                DEBUGGER.debug("ResultSet: {}", resultSet);
            }

            if (resultSet.next()) {
                resultSet.beforeFirst();
                response = new ArrayList<Object[]>();

                while (resultSet.next()) {
                    Object[] data = new Object[] { resultSet.getString(1), // svc_message_id
                            resultSet.getString(2), // svc_message_title
                            resultSet.getString(3), // svc_message_txt
                            resultSet.getString(4), // svc_message_author
                            resultSet.getTimestamp(5), // svc_message_submitdate
                            resultSet.getBoolean(6), // svc_message_active
                            resultSet.getBoolean(7), // svc_message_alert
                            resultSet.getBoolean(8), // svc_message_expires
                            resultSet.getTimestamp(9), // svc_message_expirydate
                            resultSet.getTimestamp(10), // svc_message_modifiedon
                            resultSet.getString(11) // svc_message_modifiedby
                    };

                    if (DEBUG) {
                        DEBUGGER.debug("data: {}", data);
                    }

                    response.add(data);
                }
            }
        }
    } catch (SQLException sqx) {
        ERROR_RECORDER.error(sqx.getMessage(), sqx);

        throw new SQLException(sqx.getMessage(), sqx);
    } finally {
        if (resultSet != null) {
            resultSet.close();
        }

        if (stmt != null) {
            stmt.close();
        }

        if ((sqlConn != null) && (!(sqlConn.isClosed()))) {
            sqlConn.close();
        }
    }

    return response;
}

From source file:com.nridge.core.ds.rdbms.hsqldb.HDBSQLTable.java

private void addTableRowFromFunctionResultSet(DataTable aTable, ResultSet aResultSet) {
    DataField dataField;// w w w .jav  a  2  s .  c  om
    Logger appLogger = mAppMgr.getLogger(this, "addTableRowFromFunctionResultSet");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    FieldRow fieldRow = aTable.newRow();

    int columnNumber = 0;
    for (DataField pField : aTable.getColumnBag().getFields()) {
        columnNumber++;
        dataField = new DataField(pField);

        try {
            switch (pField.getType()) {
            case Integer:
                dataField.setValue(aResultSet.getInt(columnNumber));
                break;
            case Long:
                dataField.setValue(aResultSet.getLong(columnNumber));
                break;
            case Float:
                dataField.setValue(aResultSet.getFloat(columnNumber));
                break;
            case Double:
                dataField.setValue(aResultSet.getDouble(columnNumber));
                break;
            case Boolean:
                dataField.setValue(aResultSet.getBoolean(columnNumber));
                break;
            case Date:
                dataField.setValue(aResultSet.getDate(columnNumber));
                break;
            case Time:
                dataField.setValue(aResultSet.getTime(columnNumber));
                break;
            case DateTime:
                dataField.setValue(aResultSet.getTimestamp(columnNumber));
                break;
            default:
                dataField.setValue(aResultSet.getString(columnNumber));
                break;
            }

            if (!aResultSet.wasNull())
                aTable.setValueByName(fieldRow, pField.getName(), dataField.getValue());
        } catch (SQLException e) {
            appLogger.error(String.format("SQL Exception (%s): %s", pField.getName(), e.getMessage()));
        }
    }

    aTable.addRow(fieldRow);

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);
}

From source file:data.services.ParseBaseService.java

private void updateCarOptionValues() throws SQLException, ClassNotFoundException {
    List<Car> carList = carDao.getAllAsc();
    HashMap<Long, Car> ourOldIdCarMap = new HashMap();
    HashMap<Long, CarOptionValue> fullOldIdCovMap = new HashMap();
    for (Car car : carList) {
        ourOldIdCarMap.put(car.getCmqId(), car);
        for (CarOptionValue cov : car.getCarOptionValues()) {
            fullOldIdCovMap.put(cov.getOldId(), cov);
        }/*from   w  w  w .  j a  v  a2 s .c  om*/
    }

    List<CarCompletionOption> fullCCOList = CCODao.getAllAsc();
    HashMap<Long, CarCompletionOption> ourOldIdCCOMap = new HashMap();
    for (CarCompletionOption cco : fullCCOList) {
        ourOldIdCCOMap.put(cco.getOldId(), cco);
    }

    HashSet<Long> fullOldCovIdInfoSet = new HashSet();

    List<CarOptionValue> covListForSave = new ArrayList();
    List<CarOptionValue> covListForUpdate = new ArrayList();
    List<CarOptionValue> covListForDelete = new ArrayList();

    ResultSet resSet = getFromQutoBase(
            "SELECT cmco.* FROM car_modification_completion_option cmco LEFT JOIN car_modification cm ON cmco.car_modification_id=cm.id WHERE cm.usage='ad_archive_catalog'");

    while (resSet.next()) {
        Long carOldId = resSet.getLong("car_modification_id");
        Long covOldId = resSet.getLong("id");
        fullOldCovIdInfoSet.add(covOldId);

        Double price = resSet.getDouble("price");
        String title = StringAdapter.getString(resSet.getString("title")).trim();
        String desc = StringAdapter.getString(resSet.getString("description")).trim();
        Long sort = resSet.getLong("sort");
        Boolean isPack = resSet.getBoolean("is_package");
        Long ccoOldId = resSet.getLong("car_completion_option_id");
        Long imageId = resSet.getLong("car_modification_completion_option_image_id");

        CarOptionValue cov = fullOldIdCovMap.get(covOldId);
        CarCompletionOption cco = ourOldIdCCOMap.get(ccoOldId);
        if (cco == null) {
            addError("?   ?   Quto:" + ccoOldId + "; ");
        } else {
            if (cov == null) {

                cov = new CarOptionValue();
                cov.setAudial(0);
                cov.setVisual(0);
                cov.setKinestet(0);
                cov.setCCO(cco);
                cov.setCcoOldId(ccoOldId);
                cov.setDescription(desc);
                cov.setIsPack(isPack);
                cov.setOldId(covOldId);
                cov.setTitle(title);
                cov.setSort(sort);
                cov.setCar(ourOldIdCarMap.get(carOldId));
                cov.setPrice(price);
                cov.setCovImageId(imageId);
                if (validate(cov,
                        "  ?   ?: auto_quto_id="
                                + carOldId + ", cov_quto_id=" + covOldId + ", cco_quto_id=" + ccoOldId
                                + "; ")) {
                    covListForSave.add(cov);
                }

            } else {
                if (!Objects.equals(cov.getCCO().getOldId(), ccoOldId) || !desc.equals(cov.getDescription())
                        || isPack.compareTo(cov.isIsPack()) != 0 || !title.equals(cov.getTitle())
                        || !Objects.equals(cov.getSort(), sort) || price.compareTo(cov.getPrice()) != 0
                        || !Objects.equals(cov.getCovImageId(), imageId)
                        || !Objects.equals(cov.getCar().getCmqId(), carOldId)) {
                    cov.setCCO(cco);
                    cov.setCcoOldId(ccoOldId);
                    cov.setDescription(desc);
                    cov.setIsPack(isPack);
                    cov.setOldId(covOldId);
                    cov.setTitle(title);
                    cov.setSort(sort);
                    cov.setCar(ourOldIdCarMap.get(carOldId));
                    cov.setPrice(price);
                    cov.setCovImageId(imageId);
                    if (validate(cov,
                            "  ?   : auto_quto_id="
                                    + carOldId + ", cov_quto_id=" + covOldId + ", cco_quto_id=" + ccoOldId
                                    + "; ")) {
                        covListForUpdate.add(cov);
                    }
                }
            }

        }

    }

    for (Long oldCovId : fullOldIdCovMap.keySet()) {
        if (!fullOldCovIdInfoSet.contains(oldCovId)) {
            covListForDelete.add(fullOldIdCovMap.get(oldCovId));
        }
    }

    int s = 0;
    int u = 0;
    int d = 0;
    for (CarOptionValue cov : covListForSave) {
        carOptionValueDao.save(cov);
        s++;
    }
    for (CarOptionValue cov : covListForUpdate) {
        carOptionValueDao.update(cov);
        u++;
    }
    for (CarOptionValue cov : covListForDelete) {
        carOptionValueDao.delete(cov);
        d++;
    }

    addError(" : " + s + " ?, " + u + " , " + d
            + " .");
}

From source file:com.erbjuder.logger.server.rest.util.ResultSetConverter.java

private List<LogMessage> toLogMessageInternal(ResultSet rs, List<LogMessage> logMessages) {

    try {/*from w ww. ja  va 2s . c  o  m*/

        // we will need the column names.
        java.sql.ResultSetMetaData rsmd = rs.getMetaData();
        //loop through the ResultSet
        while (rs.next()) {

            //figure out how many columns there are
            int numColumns = rsmd.getColumnCount();

            //each row in the ResultSet will be converted to a Object
            LogMessage obj = new LogMessage();

            // loop through all the columns 
            for (int i = 1; i < numColumns + 1; i++) {
                String column_name = rsmd.getColumnName(i);

                if (column_name.equals("ID")) {
                    obj.setId(rs.getBigDecimal(column_name).longValueExact());
                }

                if (column_name.equals("APPLICATIONNAME")) {
                    obj.setApplicationName(rs.getNString(column_name));
                }

                if (column_name.equals("EXPIREDDATE")) {
                    obj.setExpiredDate(rs.getDate(column_name));
                }

                if (column_name.equals("FLOWNAME")) {
                    obj.setFlowName(rs.getNString(column_name));
                }

                if (column_name.equals("FLOWPOINTNAME")) {
                    obj.setFlowPointName(rs.getNString(column_name));
                }

                if (column_name.equals("ISERROR")) {
                    obj.setIsError(rs.getBoolean(column_name));
                }

                if (column_name.equals("TRANSACTIONREFERENCEID")) {
                    obj.setTransactionReferenceID(rs.getNString(column_name));
                }

                if (column_name.equals("UTCLOCALTIMESTAMP")) {
                    obj.setUtcLocalTimeStamp(rs.getTimestamp(column_name));
                }

                if (column_name.equals("UTCSERVERTIMESTAMP")) {
                    obj.setUtcServerTimeStamp(rs.getTimestamp(column_name));
                }
            } //end foreach
            logMessages.add(obj);
        } //end while
    } catch (Exception e) {
        e.printStackTrace();
    }

    return logMessages;
}