Example usage for java.sql ResultSet getDate

List of usage examples for java.sql ResultSet getDate

Introduction

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

Prototype

java.sql.Date getDate(String columnLabel) throws SQLException;

Source Link

Document

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

Usage

From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public Auction getAuction(final int uid) {
    Auction obj = null;// w  ww.  ja va2  s . com

    Connection conn = null;
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_GETAUCTION (?)}");
        stmt.setInt(1, uid);

        rs = stmt.executeQuery();

        if (rs.next()) {
            AuctionBuilder builder = Auction.newBuilder().setUid(rs.getInt("UID"))
                    .setName(rs.getString("NAME"));

            Date startdate = rs.getDate("STARTDATE");
            if (startdate != null) {
                builder.setStartDate(startdate.getTime());
            }

            Date enddate = rs.getDate("ENDDATE");
            if (enddate != null) {
                builder.setEndDate(enddate.getTime());
            }

            builder.setLogoUrl(rs.getString("LOGOURL"));
            builder.setColor(rs.getString("COLOR"));

            obj = builder.build();
        }
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, rs);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("AUCTION [method:{} result:{}]",
                new Object[] { "get", obj != null ? obj.toString() : "[error]" });
    }

    return obj;
}

From source file:database.DataLoader.java

@Deprecated
private Date getDateOrToday(ResultSet set, String paramName) {
    try {/*from w w w . j  av  a2 s.  co m*/
        return set.getDate(paramName);
    } catch (Exception e) {
        return new Date();
    }
}

From source file:edu.arizona.kra.proposaldevelopment.dao.ojb.PropDevRoutingStateDaoOjb.java

@Override
public List<ProposalDevelopmentRoutingState> getPropDevRoutingState(Map<String, String> searchCriteria)
        throws SQLException, LookupException {
    List<ProposalDevelopmentRoutingState> results = new ArrayList<ProposalDevelopmentRoutingState>();
    HashSet<String> resultDocNumbers = new HashSet<String>();
    LOG.debug("getPropDevRoutingState searchCriteria={}", searchCriteria);

    String sqlQuery = buildSqlQuery(searchCriteria);
    boolean displayAdHocNodes = (searchCriteria.containsKey(ROUTE_STOP_NAME)
            && StringUtils.isEmpty(searchCriteria.get(ROUTE_STOP_NAME)));

    try (DBConnection dbc = new DBConnection(this.getPersistenceBroker(true))) {

        ResultSet rs = dbc.executeQuery(sqlQuery, null);

        while (rs.next()) {
            String documentNumber = rs.getString(COL_DOCUMENT_NUMBER);
            String annotation = rs.getString(COL_ANNOTATION);
            //avoid displaying more than one result row per document
            if (!resultDocNumbers.contains(documentNumber)) {
                //skip AdHoc nodes if the searchCriteria has a specific NodeName
                if (isAdHocNode(annotation) && !displayAdHocNodes) {
                    continue;
                }//from w w w  .j ava2s.  co  m
                ProposalDevelopmentRoutingState rtState = new ProposalDevelopmentRoutingState();
                rtState.setRouteStopDate(rs.getTimestamp(COL_STOP_DATE));
                rtState.setRouteStopName(getRouteStopLabel(rs.getString(COL_NODE_NAME), annotation));
                rtState.setProposalNumber(rs.getString(COL_PROPOSAL_NUMBER));
                rtState.setProposalDocumentNumber(documentNumber);
                rtState.setProposalTitle(rs.getString(COL_PROPOSAL_TITLE));
                rtState.setSponsorName(rs.getString(COL_SPONSOR_NAME));
                rtState.setSponsorCode(rs.getString(COL_SPONSOR_CODE));
                rtState.setSponsorDeadlineDate(rs.getDate(COL_SPONSOR_DEADLINE_DATE));
                rtState.setSponsorDeadlineTime(rs.getString(COL_SPONSOR_DEADLINE_TIME));
                rtState.setPrincipalInvestigatorName(rs.getString(COL_PRINCIPAL_INVESTIGATOR));
                rtState.setLeadUnitNumber(rs.getString(COL_LEAD_UNIT));
                rtState.setLeadUnitName(rs.getString(COL_LEAD_UNIT_NAME));
                rtState.setLeadCollege("");
                String ordExpedited = rs.getString(COL_ORD_EXP);
                rtState.setORDExpedited(YES.equalsIgnoreCase(ordExpedited));
                String fpr = rs.getString(COL_FPR);
                rtState.setFinalProposalReceived(YES.equalsIgnoreCase(fpr));
                rtState.setSPSPersonId(rs.getString(COL_SPS_REVIEWER_ID));
                rtState.setSPSReviewerName(rs.getString(COL_SPS_REVIEWER_NAME));
                results.add(rtState);
                resultDocNumbers.add(rtState.getProposalDocumentNumber());
            }

        }

    } catch (SQLException sqle) {
        LOG.error("SQLException: " + sqle.getMessage(), sqle);
        throw sqle;
    } catch (LookupException le) {
        LOG.error("LookupException: " + le.getMessage(), le);
        throw le;
    }

    LOG.debug("getPropDevRoutingState: no of unfiltered results={}.", results.size());

    //perform additional filtering on the results if the user specified a workflow unit
    if (!results.isEmpty() && searchCriteria.containsKey(WORKFLOW_UNIT)
            && StringUtils.isNotEmpty(searchCriteria.get(WORKFLOW_UNIT))) {
        String workflowUnit = searchCriteria.get(WORKFLOW_UNIT);
        List<String> workFlowUnits = findWorkflowUnitNumbers(workflowUnit);
        List<String> proposalNumbers = findProposalsForWorkflowUnits(workFlowUnits);

        List<ProposalDevelopmentRoutingState> filteredResults = new ArrayList<ProposalDevelopmentRoutingState>();
        for (ProposalDevelopmentRoutingState rtState : results) {
            if (proposalNumbers.contains(rtState.getProposalNumber())) {
                filteredResults.add(rtState);
            }
        }
        LOG.debug("getPropDevRoutingState: filtered results={}.", filteredResults.size());
        return filteredResults;
    }
    return results;

}

From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public List<Fund> getFundsByUser(final int userUid) {
    List<Fund> objs = Lists.newArrayList();

    Connection conn = null;/*from w w  w  . j a v a2  s .  c  o m*/
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_GETFUNDSBYUSER (?)}");
        stmt.setInt(1, userUid);

        rs = stmt.executeQuery();

        while (rs.next()) {
            FundBuilder builder = Fund.newBuilder().setUid(rs.getInt("UID")).setUserUid(rs.getInt("USERUID"))
                    .setBidPrice(rs.getDouble("FUNDPRICE")).setBidDate(rs.getDate("FUNDDATE").getTime());

            objs.add(builder.build());
        }
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, rs);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("WATCH [method:{} result:{}]", new Object[] { "get", objs.size() });
    }

    return ImmutableList.copyOf(objs);
}

From source file:beproject.MainGUI.java

private void getPredictionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_getPredictionButtonActionPerformed
    List l = null;/*from   w  ww  . j a v a  2s  . co m*/
    try {
        ResultSet rs = stmt
                .executeQuery("select releasedate from movienames where moviename='" + movieName + "'");
        rs.next();
        java.sql.Date d = rs.getDate(1), d1 = new java.sql.Date(new java.util.Date().getTime());
        if (d1.getTime() - d.getTime() > 86400000) {
            JOptionPane.showMessageDialog(null, "Prediction can only be made at release date");
            return;
        }
        l = myRegression.getRegressionValues();
        predictionTextArea.setText("");
        predictionTextArea.append("The current regression co-efficients are as follows:\n");
        predictionTextArea.append("a=" + l.get(0) + "\n");
        //predictionTextArea.append("p="+l.get(1)+"\n");
        //predictionTextArea.append("d="+l.get(2)+"\n");
        //predictionTextArea.append("c="+l.get(3)+"\n");
        //predictionTextArea.append("e="+l.get(4)+"\n");
        //predictionTextArea.append("s="+l.get(5)+"\n");
        predictionTextArea.append("=" + l.get(6) + "\n");
        predictionTextArea
                .append("With these co-efficients we predict the *OPENING WEEKEND GROSS* of the movie `"
                        + movieName + "` using the multiple linear regression equation:\n");
        //predictionTextArea.append("\tI=a*A+p*P+d*D+c*C+e*E+s*S+\n");
        predictionTextArea.append("\tI=a*(A+D)+\n");
        predictionTextArea.append("Estimated Gross in USD " + myRegression.getPrediction(movieName));
    } catch (SQLException e) {
        e.printStackTrace();
    }

}

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

/**
 * Load credit.//w ww  .  j a  v a2 s.  c o  m
 *
 * @param rs the rs
 * @param loadDetails the load details
 *
 * @return the credit bean
 *
 * @throws SQLException the SQL exception
 */
private CreditBean loadCredit(final ResultSet rs, final BuilderBean loadDetails) throws SQLException {

    CreditBean credit = new CreditBean();

    // Create resource bean and fill with dataset info.
    credit.setId(rs.getInt("CreditId"));
    credit.setGUID(rs.getInt("GUID"));

    credit.setAbbreviation(rs.getString("Abbreviation"));
    credit.setTypeName(rs.getString("Type"));
    credit.setClassName(rs.getString("CreditType"));

    credit.setNumber(rs.getString("CreditNo"));

    credit.setDescription(rs.getString("Description"));

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

    credit.setOrganisationId(rs.getInt("OrganisationId"));
    if (credit.getOrganisationId() > 0) {
        credit.setOrganisation(loadOrganisation(rs, credit.getOrganisationId(), loadDetails));
    }

    credit.setValue(rs.getDouble("Value"));
    credit.setNetValue(rs.getDouble("NetValue"));
    try {
        credit.setIssued(rs.getDate("Issued"));
    } catch (SQLException e) {
        credit.setIssued(null);
    }
    credit.setCancelled(rs.getBoolean("Cancelled"));
    credit.setGSTRate(rs.getDouble("GSTRate"));

    if (loadDetails.getBoolean("DEBITS_FULL")) {
        int debitGUID = rs.getInt("InvoiceId");
        if (debitGUID > 0) {
            DebitBean debit = new DebitBean();
            try {
                debit = this.getDebitDAO().loadGUID(debitGUID);
            } catch (Exception e) {
                dataLogger.error("Error loading debit for credit: " + e.getMessage());
            }
            if (debit.getId() > 0) {
                credit.setDebit(debit);
            }
        }
    }
    credit.setSecurity(rs.getString("Security"));

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

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

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

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

    if (loadDetails.getBoolean("CREATED")) {
        UserBean user = new UserBean();
        user.setDN(rs.getString("CreatedBy"));
        user.setPreferredName(rs.getString("CreatedFirstName"));
        user.setLastName(rs.getString("CreatedLastName"));
        credit.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"));
        credit.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"));
        credit.setExportedUser(user);
    }
    return credit;
}

From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public List<Bid> getBidsByItem(final int itemUid) {
    List<Bid> objs = Lists.newArrayList();

    Connection conn = null;/* w  w w  .ja  v  a  2 s .  c o m*/
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_GETBIDSBYITEM (?)}");
        stmt.setInt(1, itemUid);

        rs = stmt.executeQuery();

        while (rs.next()) {
            BidBuilder builder = Bid.newBuilder().setUid(rs.getInt("UID")).setItemUid(rs.getInt("ITEMUID"))
                    .setUserUid(rs.getInt("USERUID")).setBidPrice(rs.getDouble("BIDPRICE"))
                    .setBidDate(rs.getDate("BIDDATE").getTime());

            objs.add(builder.build());
        }
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, rs);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("BID [method:{} result:{}]", new Object[] { "get", objs.size() });
    }

    return ImmutableList.copyOf(objs);
}

From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public Bid getMaxBidByItem(final int itemUid) {
    Bid obj = null;//  w w  w.  j  a  va  2s.  c  o  m

    Connection conn = null;
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_GETMAXBIDBYITEM (?)}");
        stmt.setInt(1, itemUid);

        rs = stmt.executeQuery();

        if (rs.next()) {
            BidBuilder builder = Bid.newBuilder().setUid(rs.getInt("UID")).setItemUid(rs.getInt("ITEMUID"))
                    .setUserUid(rs.getInt("USERUID")).setBidPrice(rs.getDouble("BIDPRICE"))
                    .setBidDate(rs.getDate("BIDDATE").getTime());

            obj = builder.build();
        }
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, rs);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("BID [method:{} result:{}]",
                new Object[] { "get", obj != null ? obj.toString() : "[error]" });
    }

    return obj;
}

From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public List<Bid> getBidsByUser(final int userUid) {
    List<Bid> objs = Lists.newArrayList();

    Connection conn = null;//  ww w . j ava  2s.c o m
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_GETBIDSBYUSER (?)}");
        stmt.setInt(1, userUid);

        rs = stmt.executeQuery();

        while (rs.next()) {
            BidBuilder builder = Bid.newBuilder().setUid(rs.getInt("UID")).setItemUid(rs.getInt("ITEMUID"))
                    .setUserUid(rs.getInt("USERUID")).setBidPrice(rs.getDouble("BIDPRICE"))
                    .setBidDate(rs.getDate("BIDDATE").getTime());

            objs.add(builder.build());
        }
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, rs);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("BID [method:{} result:{}]", new Object[] { "get", objs.size() });
    }

    return ImmutableList.copyOf(objs);
}

From source file:org.apache.phoenix.end2end.index.IndexExpressionIT.java

private void verifyResult(ResultSet rs, int i) throws SQLException {
    assertTrue(rs.next());/*from w  ww . j  a  va2 s . c om*/
    assertEquals("VARCHAR" + String.valueOf(i) + "_" + StringUtils.rightPad("CHAR" + String.valueOf(i), 6, ' ')
            + "_A.VARCHAR" + String.valueOf(i) + "_"
            + StringUtils.rightPad("B.CHAR" + String.valueOf(i), 10, ' '), rs.getString(1));
    assertEquals(i * 3, rs.getInt(2));
    Date date = new Date(DateUtil.parseDate("2015-01-01 00:00:00").getTime() + (i) * NUM_MILLIS_IN_DAY);
    assertEquals(date, rs.getDate(3));
    assertEquals(date, rs.getDate(4));
    assertEquals(date, rs.getDate(5));
    assertEquals("varchar" + String.valueOf(i), rs.getString(6));
    assertEquals("char" + String.valueOf(i), rs.getString(7));
    assertEquals(i, rs.getInt(8));
    assertEquals(i, rs.getLong(9));
    assertEquals(i * 0.5d, rs.getDouble(10), 0.000001);
    assertEquals(i, rs.getLong(11));
    assertEquals(i, rs.getLong(12));
}