Example usage for java.sql ResultSet getDouble

List of usage examples for java.sql ResultSet getDouble

Introduction

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

Prototype

double getDouble(String columnLabel) throws SQLException;

Source Link

Document

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

Usage

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

/**
 * Load the RotationBean data.//from   ww  w. j  a  v  a 2 s. co m
 *
 * @param rs the result set
 * @param loadDetails the load details
 *
 * @return the rotation bean
 *
 * @throws SQLException the SQL exception
 */
private RotationBean loadRotation(final ResultSet rs, final BuilderBean loadDetails) throws SQLException {

    RotationBean rotation = new RotationBean();

    rotation.setId(rs.getInt("RotationId"));
    rotation.setGUID(rs.getInt("GUID"));
    rotation.setDescription(rs.getString("Description"));
    rotation.setRotationType(rs.getString("Type"));
    rotation.setRotationTypeAbbreviation(rs.getString("TypeAbbreviation"));
    rotation.setTrainingClass(rs.getString("TrainingClass"));
    rotation.setTrainingType(rs.getString("TrainingType"));
    rotation.setTrainingMapping(rs.getString("TrainingMapping"));
    rotation.setOrganisation1Name(rs.getString("OtherOrganisation1Name"));
    rotation.setOrganisation2Name(rs.getString("OtherOrganisation2Name"));
    rotation.setOrganisation1Type(rs.getString("Organisation1Type"));
    rotation.setOrganisation1TypeMapping(rs.getString("Organisation1TypeMapping"));
    rotation.setOrganisation2Type(rs.getString("Organisation2Type"));
    rotation.setOrganisation2TypeMapping(rs.getString("Organisation2TypeMapping"));
    rotation.setYear(rs.getInt("RotationYear"));
    try {
        rotation.setStartDate(rs.getDate("StartDate"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error loading StartDate: " + sqe.getMessage());
    }
    try {
        rotation.setEndDate(rs.getDate("EndDate"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error loading StartDate: " + sqe.getMessage());
    }

    rotation.setLeaveDays(rs.getInt("LeaveDays"));
    rotation.setTrainingTime(rs.getDouble("TrainingTime"));
    rotation.setCommitteeName(rs.getString("CommitteeName"));

    // Load the supervisors for this rotation
    try {
        rotation.setSupervisors(loadSupervisors(rotation.getGUID(), loadDetails));
    } catch (WhichDoctorDaoException wde) {
        dataLogger.error("Error loading supervisors: " + wde.getMessage());
    }

    rotation.setPersonId(rs.getInt("PersonId"));
    if (rotation.getPersonId() > 0) {
        rotation.setPerson(loadPerson(rotation.getPersonId(), loadDetails, rs));
    }

    rotation.setOrganisation1Id(rs.getInt("Organisation1Id"));
    if (rotation.getOrganisation1Id() > 0) {
        OrganisationBean organisation = new OrganisationBean();
        organisation.setId(rotation.getOrganisation1Id());
        organisation.setName(rs.getString("Organisation1Name"));
        organisation.setGUID(rs.getInt("Organisation1GUID"));
        rotation.setOrganisation1(organisation);
    }
    rotation.setOrganisation2Id(rs.getInt("Organisation2Id"));
    if (rotation.getOrganisation2Id() > 0) {
        OrganisationBean organisation = new OrganisationBean();
        organisation.setId(rotation.getOrganisation2Id());
        organisation.setName(rs.getString("Organisation2Name"));
        organisation.setGUID(rs.getInt("Organisation2GUID"));
        rotation.setOrganisation2(organisation);
    }

    try {
        rotation.setReports(reportDAO.load(rotation.getGUID(), loadDetails.getBoolean("REPORTS_FULL")));
    } catch (WhichDoctorDaoException wde) {
        dataLogger.error("Error loading reports: " + wde.getMessage());
    }

    if (loadDetails.getBoolean("ASSESSMENTS")) {
        try {
            rotation.setAssessment(this.assessmentDAO.load(rotation.getGUID()));
        } catch (Exception e) {
            dataLogger.error("Error loading assessment (" + rotation.getGUID() + "): " + e.getMessage());
        }
    }

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

    if (loadDetails.getBoolean("ACCREDITATIONS")) {
        try {
            rotation.setAccreditation(this.accreditationDAO.load(rotation.getGUID(),
                    loadDetails.getBoolean("ACCREDITATION_FULL")));
        } catch (Exception e) {
            dataLogger.error(
                    "Error loading accreditation details (" + rotation.getGUID() + "): " + e.getMessage());
        }
    }

    if (loadDetails.getBoolean("ONLINETOOLS")) {
        try {
            rotation.setOnlineTools(this.onlineToolDAO.loadRotation(rotation.getGUID()));
        } catch (Exception e) {
            dataLogger.error("Error loading online tools for rotation: " + e.getMessage());
        }
    }

    if (loadDetails.getBoolean("TAGS")) {
        try {
            rotation.setTags(this.getTagDAO().load(rotation.getGUID(), loadDetails.getString("USERDN"), true));
        } catch (Exception e) {
            dataLogger.error("Error loading tags for rotation: " + e.getMessage());
        }
    }

    if (loadDetails.getBoolean("MEMO")) {
        try {
            rotation.setMemo(this.getMemoDAO().load(rotation.getGUID(), loadDetails.getBoolean("MEMO_FULL")));
        } catch (Exception e) {
            dataLogger.error("Error loading memos for rotation: " + e.getMessage());
        }
    }

    if (loadDetails.getBoolean("GROUPS")) {
        rotation.setGroups(loadGroups(rotation.getGUID()));
    }

    if (loadDetails.getBoolean("CREATED")) {
        UserBean user = new UserBean();
        user.setDN(rs.getString("CreatedBy"));
        user.setPreferredName(rs.getString("CreatedFirstName"));
        user.setLastName(rs.getString("CreatedLastName"));
        rotation.setCreatedUser(user);
    }
    if (loadDetails.getBoolean("MODIFIED")) {
        UserBean user = new UserBean();
        user.setDN(rs.getString("ModifiedBy"));
        user.setPreferredName(rs.getString("ModifiedFirstName"));
        user.setLastName(rs.getString("ModifiedLastName"));
        rotation.setModifiedUser(user);
    }
    if (loadDetails.getBoolean("EXPORTED")) {
        UserBean user = new UserBean();
        user.setDN(rs.getString("ExportedBy"));
        user.setPreferredName(rs.getString("ExportedFirstName"));
        user.setLastName(rs.getString("ExportedLastName"));
        rotation.setExportedUser(user);
    }
    return rotation;
}

From source file:com.itemanalysis.jmetrik.graph.nicc.NonparametricCurveAnalysis.java

public void evaluateDIF() throws SQLException {
    Statement stmt = null;/*from www  .j a v  a  2 s  .c  o m*/
    ResultSet rs = null;

    //create focal map
    focalRegression = new TreeMap<VariableAttributes, KernelRegressionItem>();
    for (VariableAttributes v : variables) {
        KernelRegressionItem kItem = new KernelRegressionItem(v, kernelFunction, bandwidth,
                uniformDistributionApproximation);
        focalRegression.put(v, kItem);
    }

    //create reference map
    if (hasGroupVariable) {
        referenceRegression = new TreeMap<VariableAttributes, KernelRegressionItem>();
        for (VariableAttributes v : variables) {
            KernelRegressionItem kItem = new KernelRegressionItem(v, kernelFunction, bandwidth,
                    uniformDistributionApproximation);
            referenceRegression.put(v, kItem);
        }
    }

    //determine whether group variable is double or not
    boolean groupVariableIsDouble = false;
    if (groupByVariable.getType().getDataType() == DataType.DOUBLE)
        groupVariableIsDouble = true;

    try {
        //connect to db
        Table sqlTable = new Table(tableName.getNameForDatabase());
        SelectQuery select = new SelectQuery();
        for (VariableAttributes v : variables) {
            select.addColumn(sqlTable, v.getName().nameForDatabase());
        }
        select.addColumn(sqlTable, regressorVariable.getName().nameForDatabase());
        select.addColumn(sqlTable, groupByVariable.getName().nameForDatabase());

        stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        rs = stmt.executeQuery(select.toString());

        KernelRegressionItem kernelRegressionItem;
        Object itemResponse;
        Double score;
        Object tempGroup;
        String group;

        //analyze by groups
        while (rs.next()) {
            tempGroup = rs.getObject(groupByVariable.getName().nameForDatabase());
            if (tempGroup == null) {
                group = "";//will not be counted if does not match focal or reference code
            } else {
                if (groupVariableIsDouble) {
                    group = Double.valueOf((Double) tempGroup).toString();
                } else {
                    group = ((String) tempGroup).trim();
                }
            }

            //get independent variable value
            //omit examinees with missing data
            //examinees with missing group code omitted
            score = rs.getDouble(regressorVariable.getName().nameForDatabase());
            if (!rs.wasNull()) {
                if (focalCode.equals(group)) {
                    for (VariableAttributes v : focalRegression.keySet()) {
                        kernelRegressionItem = focalRegression.get(v);
                        itemResponse = rs.getObject(v.getName().nameForDatabase());
                        if (itemResponse != null)
                            kernelRegressionItem.increment(score, itemResponse);
                    }
                } else if (referenceCode.equals(group)) {
                    for (VariableAttributes v : referenceRegression.keySet()) {
                        kernelRegressionItem = referenceRegression.get(v);
                        itemResponse = rs.getObject(v.getName().nameForDatabase());
                        if (itemResponse != null)
                            kernelRegressionItem.increment(score, itemResponse);
                    }
                }
            }
            updateProgress();
        }
    } catch (SQLException ex) {
        throw ex;
    } finally {
        if (rs != null)
            rs.close();
        if (stmt != null)
            stmt.close();
    }

    this.firePropertyChange("progress-ind-on", null, null);
}

From source file:com.sdcs.courierbooking.service.UserServiceImpl.java

@Override
public String showDelBoyLocation(String userId) {

    JSONObject delBoyObject = new JSONObject();

    ResultSet delBoyMapAdmin = userDao.showDelBoyLocation(userId);
    // TODO Auto-generated method stub
    if (delBoyMapAdmin != null) {

        JSONArray delBoyMapArray = new JSONArray();
        {//from w ww  .ja  v  a 2 s .  c o m
            try {
                while (delBoyMapAdmin.next()) {

                    JSONObject delObject = new JSONObject();

                    delObject.put("lattitude", delBoyMapAdmin.getDouble("latitude"));
                    delObject.put("longittude", delBoyMapAdmin.getDouble("longitude"));
                    delObject.put("phoneNumber", delBoyMapAdmin.getString("phone"));
                    delObject.put("name", delBoyMapAdmin.getString("full_name"));

                    delBoyMapArray.put(delObject);

                }
                delBoyObject.put("status", true);
                delBoyObject.put("responceCordinates", delBoyMapArray);

                System.out.println(delBoyObject);
                delBoyMapAdmin.close();
            } catch (SQLException e) {
                delBoyObject.put("status", false);

                try {
                    delBoyMapAdmin.close();
                } catch (SQLException sqlEx) {
                    System.out.println("Exception in QuickHistoryServerImpl");
                }

            } finally {
                try {
                    delBoyMapAdmin.close();
                } catch (SQLException e) {
                    System.out.println("Exception in QuickHistoryServerImpl");
                }
            }

        }

    } else {
        delBoyObject.put("status", false);
    }
    return delBoyObject.toString();

}

From source file:com.skilrock.lms.coreEngine.accMgmt.common.ProcessPendingPWTHelper.java

/**
 * This method returns the list of games based on the search parameters
 * passed/*w  w w  . j a  va 2  s .  c  om*/
 * 
 * @param searchMap
 * @return List
 * @throws LMSException
 */
public List SearchPendingPWT(Map searchMap) throws LMSException {

    Connection connection = null;
    Statement statement = null;
    ResultSet resultSet = null;
    try {

        PlayerPWTBean playerPWTBean = null;
        List<PlayerPWTBean> searchResults = new ArrayList<PlayerPWTBean>();

        connection = DBConnect.getConnection();
        statement = connection.createStatement();

        Set keySet = null;
        keySet = searchMap.keySet();
        Iterator itr = keySet.iterator();
        String statusForSearch = null;

        while (itr.hasNext()) {
            String key = (String) itr.next();
            if (key.equals(TableConstants.PWT_STATUS)) {
                statusForSearch = (String) searchMap.get(key);
            }
        }
        logger.debug("status for search  " + statusForSearch);

        String dynamicWhereClause = getWhereClause(searchMap, statusForSearch);
        String query = null;
        if (statusForSearch.equals("CLAIM_PLR")) {

            // query="select a.pwt_receipt_id,a.player_id
            // ,a.game_id,a.transaction_date,a.virn_code,a.pwt_amt,a.tax_amt,a.net_amt,a.status,a.ticket_nbr,b.first_name,b.last_name,c.game_name,c.game_nbr,d.cheque_nbr,d.cheque_date,d.drawee_bank,d.issuing_party_name
            // from st_se_direct_player_pwt_temp_receipt a
            // ,st_lms_player_master b,st_se_game_master
            // c,st_se_direct_player_pwt d where a.game_id=c.game_id and
            // a.player_id=b.player_id and a.virn_code=d.virn_code and
            // a.game_id=d.game_id";
            query = "select a.pwt_receipt_id,a.player_id ,a.game_id,a.transaction_date,a.virn_code,a.pwt_amt,a.tax_amt,a.net_amt,a.status,a.ticket_nbr,b.first_name,b.last_name,c.game_name,c.game_nbr,d.cheque_nbr,d.cheque_date,d.drawee_bank,d.issuing_party_name from st_se_direct_player_pwt_temp_receipt a ,st_lms_player_master b,st_se_game_master c,st_se_direct_player_pwt d where a.game_id=c.game_id and a.player_id=b.player_id and a.virn_code=d.virn_code and a.game_id=d.game_id "
                    + dynamicWhereClause;
            ;
            logger.debug("in case of claim ed to player :: " + query);
        } else {
            query = QueryManager.getST5SelectDirectPlrTempTransactionQuery() + dynamicWhereClause;
        }

        logger.debug("-----Query----::" + query);

        resultSet = statement.executeQuery(query);

        while (resultSet.next()) {

            playerPWTBean = new PlayerPWTBean();
            playerPWTBean.setGameName(resultSet.getString(TableConstants.SGM_GAME_NAME));

            playerPWTBean.setGameNbr(resultSet.getInt(TableConstants.GAME_NBR));

            playerPWTBean.setGameId(resultSet.getInt(TableConstants.SGM_GAME_ID));
            playerPWTBean.setPlayerFirstName(resultSet.getString(TableConstants.PLR_FIRSTNAME));
            playerPWTBean.setPlayerLastName(resultSet.getString(TableConstants.PLR_LASTNAME));

            playerPWTBean.setPlayerId(resultSet.getInt(TableConstants.PLR_ID));
            playerPWTBean.setTrancDate(getDate(resultSet.getString(TableConstants.TRANC_DATE)).toString());
            playerPWTBean.setPwtAmt(resultSet.getDouble(TableConstants.SPI_PWT_AMT));
            playerPWTBean.setTax(resultSet.getDouble(TableConstants.TAX_AMOUNT));
            playerPWTBean.setNetAmt(resultSet.getDouble(TableConstants.SPI_NET_AMT));
            if (resultSet.getString(TableConstants.STATUS).equalsIgnoreCase("PND_PWT")) {
                playerPWTBean.setStatus("Pending PWT");

            }
            if (resultSet.getString(TableConstants.STATUS).equalsIgnoreCase("CLAIM_PLR")) {
                playerPWTBean.setStatus("Claimed PWT");

                playerPWTBean.setChequeDate(resultSet.getString("cheque_date"));
                playerPWTBean.setChequeNbr(resultSet.getString("cheque_nbr"));
                playerPWTBean.setDraweeBank(resultSet.getString("drawee_bank"));
                playerPWTBean.setTicketNbr(resultSet.getString("ticket_nbr"));

            }
            if (resultSet.getString(TableConstants.STATUS).equalsIgnoreCase("CANCEL")) {
                playerPWTBean.setStatus("Cancelled PWT");
                playerPWTBean.setChequeDate("NA");
                playerPWTBean.setChequeNbr("NA");
                playerPWTBean.setDraweeBank("NA");
            }

            playerPWTBean.setTransactionId(resultSet.getInt(TableConstants.PWT_RECEIPT_ID));
            playerPWTBean.setVirnCode(resultSet.getString(TableConstants.SPI_VIRN_CODE));
            playerPWTBean.setTicketNbr(resultSet.getString("ticket_nbr"));

            searchResults.add(playerPWTBean);

        }

        return searchResults;

    } catch (SQLException e) {
        logger.error("Exception: " + e);
        e.printStackTrace();
        throw new LMSException(e);

    } finally {

        try {

            if (statement != null) {
                statement.close();
            }
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException se) {
            logger.error("Exception: " + se);
            se.printStackTrace();
        }
    }

    // return null;

}

From source file:com.sdcs.courierbooking.service.UserServiceImpl.java

@Override
public String couriersUpdateToDeliveryBoy(Double longitude, Double latitude) {

    ResultSet courierUpdates = userDao.couriersUpdateToDeliveryBoy(longitude, latitude);
    JSONObject logoutTimeObject = new JSONObject();
    JSONArray bookedCouriers = new JSONArray();
    if (courierUpdates != null) {
        try {//from www  . j  av  a  2s .c  o m
            while (courierUpdates.next()) {
                JSONObject office = new JSONObject();
                office.put("contact_number", courierUpdates.getString("contact_number"));
                office.put("id", courierUpdates.getInt("id"));
                office.put("lat", courierUpdates.getDouble("lat"));
                office.put("longitude", courierUpdates.getDouble("longitude"));
                office.put("distance_in_km", courierUpdates.getString("distance_in_km"));
                bookedCouriers.put(office);
            }
            courierUpdates.close();

            logoutTimeObject.put("Couriers", bookedCouriers);
        } catch (SQLException e) {

            logoutTimeObject.put("Couriers", bookedCouriers);
            if (courierUpdates != null) {
                try {
                    courierUpdates.close();
                } catch (SQLException e1) {
                    System.out.println("Exception in BookingServiceImpl");
                }
            }

        }

    } else {
        return null;
    }

    return logoutTimeObject.toString();

}

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

/**
 * Load reimbursement.//w  w  w.  j ava2 s  .co  m
 *
 * @param rs the rs
 * @param loadDetails the load details
 *
 * @return the reimbursement bean
 *
 * @throws SQLException the SQL exception
 */
private ReimbursementBean loadReimbursement(final ResultSet rs, final BuilderBean loadDetails)
        throws SQLException {
    ReimbursementBean reimbursement = new ReimbursementBean();

    reimbursement.setId(rs.getInt("ReimbursementId"));
    reimbursement.setGUID(rs.getInt("GUID"));

    reimbursement.setAbbreviation(rs.getString("Abbreviation"));
    reimbursement.setClassName(rs.getString("ReimbursementClass"));
    reimbursement.setTypeName(rs.getString("ReimbursementType"));

    reimbursement.setNumber(rs.getString("ReimbursementNo"));

    reimbursement.setDescription(rs.getString("Description"));
    reimbursement.setLocation(rs.getString("Location"));
    try {
        reimbursement.setMeetingDate(rs.getDate("MeetingDate"));
    } catch (SQLException e) {
        reimbursement.setMeetingDate(null);
    }

    reimbursement.setPersonId(rs.getInt("PersonId"));
    if (reimbursement.getPersonId() > 0) {
        PersonBean person = new PersonBean();
        person.setGUID(reimbursement.getPersonId());
        person.setPersonIdentifier(rs.getInt("PersonIdentifier"));
        person.setPreferredName(rs.getString("PreferredName"));
        person.setFirstName(rs.getString("FirstName"));
        person.setLastName(rs.getString("LastName"));
        person.setTitle(rs.getString("Title"));
        person.setGender(rs.getString("Gender"));

        // Load address.
        if (loadDetails.getBoolean("ADDRESS")) {
            try {
                person.setAddress(this.getAddressDAO().load(person.getGUID(), false,
                        loadDetails.getString("ADDRESS_CLASS"), loadDetails.getString("ADDRESS_TYPE")));
            } catch (Exception e) {
                dataLogger.error("Error loading address for reimbursement: " + e.getMessage());
            }
        }
        reimbursement.setPerson(person);
    }
    reimbursement.setOrganisationId(rs.getInt("OrganisationId"));
    if (reimbursement.getOrganisationId() > 0) {
        OrganisationBean organisation = new OrganisationBean();
        organisation.setGUID(reimbursement.getOrganisationId());
        organisation.setName(rs.getString("OrganisationName"));
        if (loadDetails.getBoolean("ADDRESS")) {
            try {
                organisation.setAddress(this.getAddressDAO().load(organisation.getGUID(), false,
                        loadDetails.getString("ADDRESS_CLASS"), loadDetails.getString("ADDRESS_TYPE")));
            } catch (Exception e) {
                dataLogger.error("Error loading address for reimbursement: " + e.getMessage());
            }
        }
        reimbursement.setOrganisation(organisation);
    }
    try {
        reimbursement.setIssued(rs.getDate("Issued"));
    } catch (SQLException e) {
        reimbursement.setIssued(null);
    }
    reimbursement.setValue(rs.getDouble("ReimbursementValue"));
    reimbursement.setNetValue(rs.getDouble("ReimbursementTotalValue"));
    reimbursement.setCancelled(rs.getBoolean("Cancelled"));
    reimbursement.setSecurity(rs.getString("Security"));

    if (loadDetails.getBoolean("EXPENSECLAIM")) {
        try {
            reimbursement.setExpenseClaims(this.expenseClaimDAO.load(reimbursement.getGUID(),
                    loadDetails.getBoolean("EXPENSECLAIM_FULL")));
        } catch (Exception e) {
            dataLogger.error("Error loading expense claims for reimbursement: " + e.getMessage());
        }
    }

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

    if (loadDetails.getBoolean("TAGS")) {
        try {
            reimbursement.setTags(
                    this.getTagDAO().load(reimbursement.getGUID(), loadDetails.getString("USERDN"), true));
        } catch (Exception e) {
            dataLogger.error("Error loading tags for reimbursement: " + e.getMessage());
        }
    }

    if (loadDetails.getBoolean("MEMO")) {
        try {
            reimbursement.setMemo(
                    this.getMemoDAO().load(reimbursement.getGUID(), loadDetails.getBoolean("MEMO_FULL")));
        } catch (Exception e) {
            dataLogger.error("Error loading memos for reimbursement: " + e.getMessage());
        }
    }

    if (loadDetails.getBoolean("GROUPS")) {
        reimbursement.setGroups(loadGroups(reimbursement.getGUID()));
    }

    if (loadDetails.getBoolean("CREATED")) {
        UserBean user = new UserBean();
        user.setDN(rs.getString("CreatedBy"));
        user.setPreferredName(rs.getString("CreatedFirstName"));
        user.setLastName(rs.getString("CreatedLastName"));
        reimbursement.setCreatedUser(user);
    }
    if (loadDetails.getBoolean("MODIFIED")) {
        UserBean user = new UserBean();
        user.setDN(rs.getString("ModifiedBy"));
        user.setPreferredName(rs.getString("ModifiedFirstName"));
        user.setLastName(rs.getString("ModifiedLastName"));
        reimbursement.setModifiedUser(user);
    }
    if (loadDetails.getBoolean("EXPORTED")) {
        UserBean user = new UserBean();
        user.setDN(rs.getString("ExportedBy"));
        user.setPreferredName(rs.getString("ExportedFirstName"));
        user.setLastName(rs.getString("ExportedLastName"));
        reimbursement.setExportedUser(user);
    }
    return reimbursement;
}

From source file:com.sdcs.courierbooking.service.UserServiceImpl.java

@Override
public String deliveryBoyLogin(Integer HtHorNml) {
    JSONObject deliveryTracking = new JSONObject();
    ResultSet resultsettracking = userDao.deliveryBoyLogin(HtHorNml);
    JSONArray trackingArray = new JSONArray();
    if (resultsettracking != null)
        try {//  w w  w  .  j a v  a2  s. co  m
            while (resultsettracking.next()) {
                JSONObject tracking = new JSONObject();
                if (HtHorNml == 2) {
                    tracking.put("user_id", resultsettracking.getInt("user_id"));
                } else {
                    tracking.put("user_id", resultsettracking.getInt("office_id"));
                }
                tracking.put("latitude", resultsettracking.getDouble("latitude"));
                tracking.put("longitude", resultsettracking.getDouble("longitude"));
                trackingArray.put(tracking);
            }
            deliveryTracking.put("status", true);
            deliveryTracking.put("tracking", trackingArray);
            resultsettracking.close();
        } catch (SQLException e) {
            deliveryTracking.put("status", false);

            try {
                resultsettracking.close();
            } catch (SQLException sqlEx) {
                System.out.println("Exception in QuickHistoryServerImpl");
            }

        } finally {
            try {
                resultsettracking.close();
            } catch (SQLException e) {
                System.out.println("Exception in QuickHistoryServerImpl");
            }
        }

    else {
        deliveryTracking.put("status", false);
    }
    return deliveryTracking.toString();
}

From source file:jp.mathes.databaseWiki.db.postgres.PostgresBackend.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override/* w w w. ja  v  a2  s  .  c om*/
public Document getDocument(final String user, final String password, final String db, final String table,
        final String name, final boolean allowEmpty, final Map<String, String[]> defaultFieldValues)
        throws BackendException {
    Connection conn = null;
    Statement st = null;
    ResultSet rs = null;
    try {
        conn = this.connectToDB(user, password, db);
        PostgresDocument doc = this.createEmptyDocument(conn, table, name, db);
        String nameField = this.getNameField(conn, table, db);
        st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        String queryString = String.format("select * from \"%s\".\"%s\" where \"%s\"='%s'",
                this.getSchemaName(table, db), this.getPlainTableName(table), nameField, name);
        this.logString(queryString, user);
        rs = st.executeQuery(queryString);
        if (this.getNumRows(rs) == 0) {
            if (allowEmpty) {
                if (defaultFieldValues != null) {
                    for (String key : defaultFieldValues.keySet()) {
                        Field field = doc.getAllFields().get(key);
                        if (field != null) {
                            if (field.getType() == FieldType.string || field.getType() == FieldType.text) {
                                field.setValue(defaultFieldValues.get(key)[0]);
                            } else if (field.getType() == FieldType.date) {
                                try {
                                    field.setValue(new SimpleDateFormat("y-M-d")
                                            .parse(defaultFieldValues.get(key)[0]));
                                } catch (ParseException e) {
                                    throw new BackendException(e);
                                }
                            } else if (field.getType() == FieldType.dec) {
                                field.setValue(Integer.valueOf(defaultFieldValues.get(key)[0]));
                            } else if (field.getType() == FieldType.num) {
                                field.setValue(Double.valueOf(defaultFieldValues.get(key)[0]));
                            }
                        }
                    }
                }
                return doc;
            } else {
                throw new DocumentNotFoundException(String.format("Document '%s' not found in table '%s.%s'.",
                        name, this.getSchemaName(table, db), this.getPlainTableName(table)));
            }
        }
        rs.next();
        ResultSetMetaData md = rs.getMetaData();
        for (int i = 1; i <= md.getColumnCount(); i++) {
            Field field = doc.getAllFields().get(md.getColumnName(i));
            if (field.getType() == FieldType.string || field.getType() == FieldType.text) {
                field.setValue(rs.getString(i));
            } else if (field.getType() == FieldType.date) {
                field.setValue(rs.getDate(i));
            } else if (field.getType() == FieldType.dec) {
                field.setValue(rs.getInt(i));
            } else if (field.getType() == FieldType.num) {
                field.setValue(rs.getDouble(i));
            }
        }
        return doc;
    } catch (SQLException e) {
        throw new BackendException(e);
    } catch (ClassNotFoundException e) {
        throw new BackendException(e);
    } finally {
        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(st);
        DbUtils.closeQuietly(conn);
    }
}

From source file:massbank.DatabaseManager.java

public Record getAccessionData(String accessionId, String contributor) {
    Record acc = new Record(contributor);
    try {//from w w w  .  ja v a  2  s .com
        this.statementRECORD.setString(1, accessionId);
        ResultSet set = this.statementRECORD.executeQuery();
        int compoundID = -1;
        int sampleID = -1;
        int instrumentID = -1;
        if (set.next()) {
            acc.ACCESSION(set.getString("ACCESSION"));
            acc.RECORD_TITLE(set.getString("RECORD_TITLE"));
            acc.DATE(set.getDate("DATE").toLocalDate());
            acc.AUTHORS(set.getString("AUTHORS"));
            acc.LICENSE(set.getString("LICENSE"));
            acc.COPYRIGHT(set.getString("COPYRIGHT"));
            acc.PUBLICATION(set.getString("PUBLICATION"));
            compoundID = set.getInt("CH");
            sampleID = set.getInt("SP");
            instrumentID = set.getInt("AC_INSTRUMENT");
            acc.AC_MASS_SPECTROMETRY_MS_TYPE(set.getString("AC_MASS_SPECTROMETRY_MS_TYPE"));
            acc.AC_MASS_SPECTROMETRY_ION_MODE(set.getString("AC_MASS_SPECTROMETRY_ION_MODE"));
            acc.PK_SPLASH(set.getString("PK_SPLASH"));
            this.statementAC_CHROMATOGRAPHY.setString(1, set.getString("ACCESSION"));
            this.statementAC_MASS_SPECTROMETRY.setString(1, set.getString("ACCESSION"));
            this.statementMS_DATA_PROCESSING.setString(1, set.getString("ACCESSION"));
            this.statementMS_FOCUSED_ION.setString(1, set.getString("ACCESSION"));
            this.statementCOMMENT.setString(1, set.getString("ACCESSION"));
            this.statementPEAK.setString(1, set.getString("ACCESSION"));
            this.statementPK_NUM_PEAK.setString(1, set.getString("ACCESSION"));
            this.statementANNOTATION_HEADER.setString(1, accessionId);

            ResultSet tmp = this.statementAC_CHROMATOGRAPHY.executeQuery();
            List<Pair<String, String>> tmpList = new ArrayList<Pair<String, String>>();
            while (tmp.next())
                tmpList.add(Pair.of(tmp.getString("SUBTAG"), tmp.getString("VALUE")));
            acc.AC_CHROMATOGRAPHY(tmpList);

            tmp = this.statementAC_MASS_SPECTROMETRY.executeQuery();
            tmpList.clear();
            while (tmp.next())
                tmpList.add(Pair.of(tmp.getString("SUBTAG"), tmp.getString("VALUE")));
            acc.AC_MASS_SPECTROMETRY(tmpList);

            tmp = this.statementMS_DATA_PROCESSING.executeQuery();
            tmpList.clear();
            while (tmp.next())
                tmpList.add(Pair.of(tmp.getString("SUBTAG"), tmp.getString("VALUE")));
            acc.MS_DATA_PROCESSING(tmpList);

            tmp = this.statementMS_FOCUSED_ION.executeQuery();
            tmpList.clear();
            while (tmp.next())
                tmpList.add(Pair.of(tmp.getString("SUBTAG"), tmp.getString("VALUE")));
            acc.MS_FOCUSED_ION(tmpList);

            tmp = this.statementCOMMENT.executeQuery();
            List<String> tmpList2 = new ArrayList<String>();
            while (tmp.next())
                tmpList2.add(tmp.getString("COMMENT"));
            acc.COMMENT(tmpList2);

            tmp = this.statementANNOTATION_HEADER.executeQuery();
            //            int PK_ANNOTATION_HEADER_numberOfTokens   = -1;
            if (tmp.next()) {
                String PK_ANNOTATION_HEADER = tmp.getString("HEADER");
                String[] PK_ANNOTATION_HEADER_tokens = PK_ANNOTATION_HEADER.split(" ");
                acc.PK_ANNOTATION_HEADER(Arrays.asList(PK_ANNOTATION_HEADER_tokens));
                //               PK_ANNOTATION_HEADER_numberOfTokens   = PK_ANNOTATION_HEADER_tokens.length;
            }

            tmp = this.statementPEAK.executeQuery();
            //            acc.add("PK$PEAK", null, "m/z int. rel.int.");
            while (tmp.next()) {
                acc.PK_PEAK_ADD_LINE(Arrays.asList((Double) tmp.getDouble("PK_PEAK_MZ"),
                        (Double) (double) tmp.getFloat("PK_PEAK_INTENSITY"),
                        (Double) (double) tmp.getShort("PK_PEAK_RELATIVE")));
                String PK_ANNOTATION = tmp.getString("PK_ANNOTATION");
                if (PK_ANNOTATION != null)
                    acc.PK_ANNOTATION_ADD_LINE(Arrays.asList(PK_ANNOTATION.split(" ")));
            }
            tmp = this.statementPK_NUM_PEAK.executeQuery();
            while (tmp.next()) {
                acc.PK_NUM_PEAK(Integer.valueOf(tmp.getInt("PK_NUM_PEAK")));
            }
        } else
            throw new IllegalStateException("accessionId '" + accessionId + "' is not in database");
        if (compoundID == -1)
            throw new IllegalStateException("compoundID is not set");
        this.statementCOMPOUND.setInt(1, compoundID);
        set = this.statementCOMPOUND.executeQuery();
        while (set.next()) {
            String formulaString = set.getString("CH_FORMULA");
            IMolecularFormula m = MolecularFormulaManipulator.getMolecularFormula(formulaString,
                    DefaultChemObjectBuilder.getInstance());
            acc.CH_FORMULA(m);
            acc.CH_EXACT_MASS(set.getDouble("CH_EXACT_MASS"));

            String smilesString = set.getString("CH_SMILES");
            if (smilesString.equals("N/A"))
                acc.CH_SMILES(new AtomContainer());
            else {
                IAtomContainer c = new SmilesParser(DefaultChemObjectBuilder.getInstance())
                        .parseSmiles(smilesString);
                acc.CH_SMILES(c);
            }

            String iupacString = set.getString("CH_IUPAC");
            if (iupacString.equals("N/A"))
                acc.CH_IUPAC(new AtomContainer());
            else {
                // Get InChIToStructure
                InChIToStructure intostruct = InChIGeneratorFactory.getInstance()
                        .getInChIToStructure(iupacString, DefaultChemObjectBuilder.getInstance());
                INCHI_RET ret = intostruct.getReturnStatus();
                if (ret == INCHI_RET.WARNING) {
                    // Structure generated, but with warning message
                    System.out.println(acc.ACCESSION() + ": InChI warning: " + intostruct.getMessage());
                } else if (ret != INCHI_RET.OKAY) {
                    // Structure generation failed
                    throw new IllegalArgumentException(
                            "Can not parse INCHI string in \"CH$IUPAC\" field. Structure generation failed: "
                                    + ret.toString() + " [" + intostruct.getMessage() + "] for " + iupacString);
                }
                IAtomContainer iupac = intostruct.getAtomContainer();
                acc.CH_IUPAC(iupac);
            }

            // TODO CH$CDK_DEPICT_SMILES
            // TODO CH$CDK_DEPICT_GENERIC_SMILES
            // TODO CH$CDK_DEPICT_STRUCTURE_SMILES
            //            acc.add("CH$CDK_DEPICT_SMILES", null, set.getString("CH_CDK_DEPICT_SMILES"));
            //            acc.add("CH$CDK_DEPICT_GENERIC_SMILES", null, set.getString("CH_CDK_DEPICT_GENERIC_SMILES"));
            //            acc.add("CH$CDK_DEPICT_STRUCTURE_SMILES", null, set.getString("CH_CDK_DEPICT_STRUCTURE_SMILES"));
        }
        this.statementCH_LINK.setInt(1, compoundID);
        set = this.statementCH_LINK.executeQuery();
        List<Pair<String, String>> tmpList = new ArrayList<Pair<String, String>>();
        while (set.next()) {
            tmpList.add(Pair.of(set.getString("DATABASE_NAME"), set.getString("DATABASE_ID")));
        }
        acc.CH_LINK(tmpList);

        this.statementCOMPOUND_COMPOUND_CLASS.setInt(1, compoundID);
        set = this.statementCOMPOUND_COMPOUND_CLASS.executeQuery();
        List<String> tmpList2 = new ArrayList<String>();
        while (set.next()) {
            this.statementCOMPOUND_CLASS.setInt(1, set.getInt("CLASS"));
            ResultSet tmp = this.statementCOMPOUND_CLASS.executeQuery();
            while (tmp.next()) {
                tmpList2.add(tmp.getString("CH_COMPOUND_CLASS"));
            }
        }
        acc.CH_COMPOUND_CLASS(tmpList2);

        this.statementCOMPOUND_NAME.setInt(1, compoundID);
        set = this.statementCOMPOUND_NAME.executeQuery();
        tmpList2.clear();
        while (set.next()) {
            this.statementNAME.setInt(1, set.getInt("NAME"));
            ResultSet tmp = this.statementNAME.executeQuery();
            while (tmp.next()) {
                tmpList2.add(tmp.getString("CH_NAME"));
            }
        }
        acc.CH_NAME(tmpList2);

        this.statementSAMPLE.setInt(1, sampleID);
        set = this.statementSAMPLE.executeQuery();
        if (set.next()) {
            acc.SP_SCIENTIFIC_NAME(set.getString("SP_SCIENTIFIC_NAME"));
            acc.SP_LINEAGE(set.getString("SP_LINEAGE"));

            this.statementSP_LINK.setInt(1, set.getInt("ID"));
            ResultSet tmp = this.statementSP_LINK.executeQuery();
            tmpList.clear();
            while (tmp.next()) {
                String spLink = tmp.getString("SP_LINK");
                String[] tokens = spLink.split(" ");
                tmpList.add(Pair.of(tokens[0], tokens[1]));
            }
            acc.SP_LINK(tmpList);

            this.statementSP_SAMPLE.setInt(1, set.getInt("ID"));
            tmp = this.statementSP_SAMPLE.executeQuery();
            tmpList2.clear();
            while (tmp.next()) {
                tmpList2.add(tmp.getString("SP_SAMPLE"));
            }
            acc.SP_SAMPLE(tmpList2);
        }
        if (instrumentID == -1)
            throw new IllegalStateException("instrumentID is not set");
        this.statementINSTRUMENT.setInt(1, instrumentID);
        set = this.statementINSTRUMENT.executeQuery();
        if (set.next()) {
            acc.AC_INSTRUMENT(set.getString("AC_INSTRUMENT"));
            acc.AC_INSTRUMENT_TYPE(set.getString("AC_INSTRUMENT_TYPE"));
        } else
            throw new IllegalStateException("instrumentID is not in database");
    } catch (Exception e) {
        System.out.println("error: " + accessionId);
        e.printStackTrace();
        return null;
    }
    //      this.openConnection();

    return acc;
}

From source file:com.ibm.bluemix.samples.PostgreSQLClient.java

/**
 * Grab text from PostgreSQL// w  w  w.j a  v  a2s.com
 * 
 * @return List of Strings of text from PostgreSQL
 * @throws Exception
 */
public List<EntityTrack> getTrackList(String notesID, String roleID) throws Exception {
    StringBuilder sqlBuilder = new StringBuilder();
    sqlBuilder.append("SELECT * FROM track");
    if (!roleID.equals("1000")) {
        String str = String.format(" where NotesID='%s'", notesID);
        sqlBuilder.append(str);
    }
    sqlBuilder.append(" order by AddDate desc");

    Connection connection = null;
    PreparedStatement statement = null;
    ResultSet results = null;
    EntityTrack track = null;
    List<EntityTrack> trackList = new ArrayList<EntityTrack>();

    try {
        connection = getConnection();
        statement = connection.prepareStatement(sqlBuilder.toString());
        results = statement.executeQuery();

        while (results.next()) {
            track = new EntityTrack();
            if (results.getString("NotesID") != null) {
                track.setNotesID(results.getString("NotesID"));
            }
            if (results.getString("LiquidID") != null) {
                track.setLiquidID(results.getString("LiquidID"));
            }
            if (results.getString("Name") != null) {
                track.setName(results.getString("Name"));
            }
            if (results.getString("TechDomain") != null) {
                track.setTechDomain(results.getString("TechDomain"));
                track.setTechDisp(CommMethod.changeTechnology(results.getString("TechDomain"),
                        results.getString("TechOther")));
            }
            if (results.getString("TechOther") != null) {
                track.setTechOther(results.getString("TechOther"));
            }
            if (results.getString("EventType") != null) {
                track.setEventType(results.getString("EventType"));
                track.setEventDisp(CommMethod.changeEvent(results.getString("EventType"),
                        results.getString("EventOther")));
            }
            if (results.getString("EventOther") != null) {
                track.setEventOther(results.getString("EventOther"));
            }
            if (results.getString("RegisterDate") != null) {
                track.setRegisterDate(results.getString("RegisterDate"));
            }
            if (results.getString("CompleteDate") != null) {
                track.setCompleteDate(results.getString("CompleteDate"));
            }
            if (results.getString("Status") != null) {
                track.setStatus(results.getString("Status"));
                track.setStatusDisp(CommMethod.changeStatus(results.getString("Status")));
            }
            if (results.getString("IsFirst") != null) {
                track.setIsFirst(results.getString("IsFirst"));
                track.setIsFirstDisp(CommMethod.changeFlag(results.getString("IsFirst")));
            }
            if (results.getString("IsSecond") != null) {
                track.setIsSecond(results.getString("IsSecond"));
                track.setIsSecondDisp(CommMethod.changeFlag(results.getString("IsSecond")));
            }

            track.setWinDollar(results.getDouble("WinDollar"));
            track.setWinHour(results.getDouble("WinHour"));
            track.setWinPoint(results.getDouble("WinPoint"));
            trackList.add(track);
        }
        return trackList;
    } catch (SQLException e) {
        throw e;
    } finally {
        if (results != null) {
            results.close();
        }

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

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