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.webbfontaine.valuewebb.model.listeners.ClientValueSetter.java

public void setIdfDate(TtGen ttGen) {
    if (ApplicationProperties.isFisIdfServiceEnabled()) {
        String idfNumber = ttGen.getIdfNum();
        Connection connection = Utils.getSQLConnection();
        ResultSet rs = null;
        PreparedStatement preparedStatement = null;
        String sql = "select idf_date from idf, idf_details where idf.idf_details_id = idf_details.id and idf_number = ?";
        try {/*from  w ww.  ja v a  2 s .  c o  m*/
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, idfNumber);
            rs = preparedStatement.executeQuery();

            if (rs.next()) {
                ttGen.setIdfDate(rs.getDate("IDF_DATE"));
            }
        } catch (SQLException e) {
            LOGGER.error(e, "");
        } finally {
            DBUtils.closeResources(rs, preparedStatement, connection);
        }
    }
}

From source file:CatalogWSModel.CatalogWS.java

/**
 * This is a sample web service operation
 *///from  w  ww. jav  a 2  s  . c om
@WebMethod(operationName = "viewCatalog")
public ArrayList<String> viewCatalog(@WebParam(name = "access_token") String access_token)
        throws IOException, ParseException {
    int status = 0;
    ArrayList<String> answers = new ArrayList<String>();
    Connection dbConn = DbConnectionManager.getConnection();
    String targetIS = "ValidateToken";
    String urlParameters = "access_token=" + access_token;
    HttpURLConnection urlConn = UrlConnectionManager.doReqPost(targetIS, urlParameters);
    String resp = UrlConnectionManager.getResponse(urlConn);
    JSONParser parser = new JSONParser();
    JSONObject obj = (JSONObject) parser.parse(resp);
    String statusResp = (String) obj.get("status");
    String username = (String) obj.get("username");
    System.out.println("obj= " + obj.get("user_id"));
    String user_id = (String) obj.get("user_id");
    System.out.println("String id = " + user_id);
    switch (statusResp) {
    case "valid":
        try {
            String query = "SELECT * FROM catalogue Order by product_id DESC";

            Statement ps = dbConn.createStatement();
            ResultSet rs = ps.executeQuery(query);
            while (rs.next()) {
                String productname = rs.getString("productname");
                String seller = rs.getString("username");
                int product_id = rs.getInt("product_id");
                int price = rs.getInt("price");
                String productdesc = rs.getString("productdesc");
                Date dateAddedF = rs.getDate("dateadded");
                SimpleDateFormat simpledatafo = new SimpleDateFormat("dd/MM/yyyy");
                Time timeAddedF = rs.getTime("timeadded");
                SimpleDateFormat simpletimefo = new SimpleDateFormat("dd/MM/yyyy");
                String dateadded = rs.getString("dateadded");
                String timeadded = rs.getString("timeadded");
                String qLike = "SELECT * from likes WHERE product_id='" + product_id + "'";
                Statement psLike = dbConn.createStatement();
                ResultSet rsLike = psLike.executeQuery(qLike);
                int count = 0;
                while (rsLike.next()) {
                    count++;
                }
                int likes = count;
                int purchases = rs.getInt("purchases");
                String imagepath = rs.getString("imagepath");

                String statuslike = "<span><a id=\"like\" href=\"like?product_id=" + product_id
                        + "\"><b>ASD</b></a></span>";
                String checkLike = "SELECT * from likes WHERE product_id='" + product_id + "' AND user_id='"
                        + user_id + "'";
                boolean hasLiked;
                Statement psCheckLike = dbConn.createStatement();
                ResultSet rsCheckLike = psLike.executeQuery(checkLike);
                hasLiked = rsCheckLike.next();

                if (!hasLiked) {
                    statuslike = "<span><a id=\"like\" href=\"like?product_id=" + product_id
                            + "\"><b>LIKE</b></a></span>";
                } else {
                    statuslike = "<span><a id=\"dislike\" href=\"dislike?product_id=" + product_id
                            + "\"><b>LIKED</b></a></span>";
                }
                String answer = "<li>" + "<span id='date'>" + "<b>" + seller + "</b>" + "</span>" + "<br/>"
                        + "<span id='date'>" + dateadded + "<br/>" + "at " + timeadded + "<hr></hr>" + "</span>"
                        + "<div class='item-list-product'>" + "<div style='position:absolute'>" + "<a href='"
                        + imagepath + "'><img class='img-item' src='" + imagepath + "'></img></a>" + "</div>"
                        + "<div id='product-info'>" + "<span><b>" + productname + "</b></span> <br/>"
                        + "<span>IDR " + price + "</span> <br/>"
                        + "<span style='font-size:12px;position:relative'>" + productdesc + "</span>" + "</div>"
                        + "<div id='eddel'>" + "<br/>" + "<span style='font-size:14px'>" + likes
                        + " likes</span> <br/>" + "<span style='font-size:14px'>" + purchases
                        + " purchase</span> <br/>" + "<br/>" + statuslike
                        + "<span style='margin-left:10px'><a id='buy' href='confirm.jsp?product_id="
                        + product_id + "'><b>    BUY </b></a> </span>" + "</div>" + "</div>" + "</li>"
                        + "<br/><br/>";
                answers.add(answer);
            }
        } catch (SQLException ex) {
            System.out.println("Insert to database failed: An Exception has occurred! " + ex);
        }

        break;
    case "non-valid":
        String answer = "2";
        answers.add(answer);
        break;
    default:
        answer = "3";
        answers.add(answer);
        break;
    }
    System.out.println("Answer = " + answers.get(0));
    return answers;
}

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

/**
 * Load expense claim.//from ww  w  . j a v  a  2  s.  c o m
 *
 * @param rs the rs
 * @return the expense claim bean
 * @throws SQLException the sQL exception
 */
private ExpenseClaimBean loadExpenseClaim(final ResultSet rs) throws SQLException {

    ExpenseClaimBean expenseClaim = new ExpenseClaimBean();

    expenseClaim.setId(rs.getInt("ExpenseClaimId"));
    expenseClaim.setGUID(rs.getInt("GUID"));
    expenseClaim.setReferenceGUID(rs.getInt("ReferenceGUID"));
    expenseClaim.setExpenseClass(rs.getString("ExpenseClass"));
    expenseClaim.setExpenseType(rs.getString("ExpenseType"));
    expenseClaim.setCurrencyAbbreviation(rs.getString("CurrencyAbbreviation"));
    try {
        expenseClaim.setExpenseDate(rs.getDate("ExpenseDate"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error loading ExpenseDate: " + sqe.getMessage());
    }
    expenseClaim.setExchangeRate(rs.getDouble("ExchangeRate"));
    expenseClaim.setDescription(rs.getString("Description"));
    expenseClaim.setRate(rs.getDouble("Rate"));
    expenseClaim.setQuantity(rs.getInt("Quantity"));
    expenseClaim.setGSTRate(rs.getDouble("GSTRate"));
    expenseClaim.setValue(rs.getDouble("Value"));
    expenseClaim.setNetValue(rs.getDouble("NetValue"));

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

    return expenseClaim;
}

From source file:nl.tudelft.stocktrader.mysql.MySQLCustomerDAO.java

public Account getCustomerByUserId(String userId) throws DAOException {
    PreparedStatement getCustomerByUserId = null;

    try {// www. j ava2s . c o m
        getCustomerByUserId = sqlConnection.prepareStatement(SQL_SELECT_GET_CUSTOMER_BY_USERID);
        getCustomerByUserId.setString(1, userId);
        ResultSet rs = getCustomerByUserId.executeQuery();
        if (rs.next()) {
            try {
                Account bean = new Account(rs.getInt(1), rs.getString(2),
                        StockTraderUtility.convertToCalendar(rs.getDate(3)), rs.getBigDecimal(4), rs.getInt(5),
                        rs.getBigDecimal(6), StockTraderUtility.convertToCalendar(rs.getDate(7)), rs.getInt(8));
                return bean;
            } finally {
                try {
                    rs.close();
                } catch (SQLException e) {
                    logger.debug("", e);
                }
            }
        }
    } catch (SQLException e) {
        throw new DAOException("", e);
    } finally {
        if (getCustomerByUserId != null) {
            try {
                getCustomerByUserId.close();
            } catch (SQLException e) {
                logger.debug("", e);
            }
        }
    }
    return null;
}

From source file:com.adito.jdbc.JDBCUserDatabase.java

public User logon(String username, String password)
        throws UserDatabaseException, InvalidLoginCredentialsException, AccountLockedException {
    JDBCPreparedStatement ps = null;/* w  w w.ja  va 2 s.c o  m*/
    try {
        ps = db.getStatement("logon.user");
        ps.setString(1, username);
        ps.setString(2, password);
        ps.setInt(3, realm.getResourceId());
        ResultSet results = ps.executeQuery();
        try {
            while (results.next()) {
                try {
                    DefaultUser user = new DefaultUser(results.getString("username"),
                            results.getString("email"), results.getString("fullname"),
                            results.getDate("last_password_change"),
                            UserDatabaseManager.getInstance().getRealm(results.getInt("realm_ID")));
                    addRoles(user);
                    return user;
                } catch (Exception e) {
                    throw new UserDatabaseException("Failed to get user realm.");
                }
            }
        } finally {
            results.close();
        }
    } catch (UserDatabaseException ude) {
        throw ude;
    } catch (SQLException ex) {
        throw new UserDatabaseException("Failed to execute SQL query", ex);
    } catch (ClassNotFoundException ex) {
        throw new UserDatabaseException("Failed to execute SQL query", ex);
    } finally {
        try {
            if (ps != null) {
                ps.releasePreparedStatement();
            }
        } catch (SQLException e) {
        }
    }
    throw new InvalidLoginCredentialsException();
}

From source file:CSVWriter.java

private String handleDate(ResultSet rs, int columnIndex) throws SQLException {
    java.sql.Date date = rs.getDate(columnIndex);
    String value = null;/*from w w w  .  j a v a2s  .com*/
    if (date != null) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
        value = dateFormat.format(date);
    }
    return value;
}

From source file:com.apbc.dao.AgentPayablesDAO.java

/**
 * select * from asbckodbnew.agent_payables
where payment_date/*ww w.j  av a 2s. c  o  m*/
BETWEEN CAST('2016-01-01' AS DATE) AND CAST('2016-01-15' AS DATE)
;
 * @param lic TODO
 * @param i
 * @param j
        
 * @return
 */

public List<ExtractedAgentPaymentDetails> getPayablesRow(PayPeriod pp, final KnownAgentDAO agent,
        final AgentLicenceDAO lic) {
    Date d1 = pp.getFromDate();
    Date d2 = pp.getToDate();
    final Date d3 = pp.getUptoExtractDate();
    final Integer payperiodid = Integer.valueOf(pp.getPayperiodId());
    return template.query(
            "select *  from agent_payables " + "where payment_date <= '" + d3 + "' and status !=" + "'Paid'",

            new RowMapper<ExtractedAgentPaymentDetails>() {
                @Override
                public ExtractedAgentPaymentDetails mapRow(ResultSet rs, int rownumber) throws SQLException {
                    ExtractedAgentPaymentDetails e = new ExtractedAgentPaymentDetails();
                    e.setAgent_id(rs.getInt("agent_id"));
                    e.setPolicyid(rs.getString("policy_id"));
                    e.setCarrierid(rs.getInt("carrier_id"));
                    e.setProductcode(rs.getString("product_code"));
                    e.setAgentcommission(rs.getLong("agent_earned_commission"));
                    e.setCommissiontype(rs.getString("commission_type"));
                    e.setPaymentdate(rs.getDate("payment_date"));
                    e.setCreationdate(rs.getDate("creation_date"));
                    e.setPayperiodupto(d3); //PAYPERIOD UP TO COMING FROM STATIC TABLE FOR GIVEN PAY PERIOD ID TODO
                    e.setPayperiod(Integer.valueOf(payperiodid)); //TODO FROM PAYPERIOD INPUT VALUE
                    //e.setAgent_name("TEST NAME"); //TODO GET AGENT NAME FROM AGENT TABLE BY PROVIDING ID;
                    e.setAgent_name(getAgentName(agent, rs.getInt("agent_id")));
                    e.setAgentlicnum(getAgentLic(lic, rs.getInt("agent_id"))); // TODO get from agentlicensed table
                    e.setTrasactiontype(rs.getInt("transaction_type"));
                    e.setDesc("NORMAL");
                    return e;
                }

                private String getAgentLic(AgentLicenceDAO lic, int agentId) {
                    return lic.findByAgentId(Integer.valueOf(agentId));
                }
            });
}

From source file:com.havoc.hotel.admin.dao.impl.CustomerDAOImpl.java

@Override
public Customer getById(int customerId) throws SQLException {
    return (Customer) jdbcTemplate.query(SQLConstant.CUSTOMER_GETBYID, new Object[] { customerId },
            new ResultSetExtractor<Customer>() {

                @Override/*from   w  w  w.  j  av  a 2s  .  c o  m*/
                public Customer extractData(ResultSet rs) throws SQLException, DataAccessException {
                    Customer c = null;
                    if (rs.next()) {
                        c = new Customer();
                        c.setCustomerId(rs.getInt("customer_id"));
                        c.setFirstName(rs.getString("first_name"));
                        c.setLastName(rs.getString("last_name"));
                        c.setEmail(rs.getString("email"));
                        c.setContactNo(rs.getString("contact_no"));
                        c.setUsername(rs.getString("username"));
                        c.setPassword(rs.getString("password"));
                        c.setAddedDate(rs.getDate("added_date"));
                        c.setStatus(rs.getBoolean("status"));
                    }
                    return c;
                }
            });
}

From source file:com.havoc.hotel.admin.dao.impl.CustomerDAOImpl.java

@Override
public Customer authenticate(String username, String password) {
    return (Customer) jdbcTemplate.query(SQLConstant.CUSTOMER_AUTHENTICATE, new Object[] { username, password },
            new ResultSetExtractor<Customer>() {

                @Override/* w  ww.  j  a  v  a 2s  .c o m*/
                public Customer extractData(ResultSet rs) throws SQLException, DataAccessException {
                    Customer c = null;
                    if (rs.next()) {
                        c = new Customer();
                        c.setCustomerId(rs.getInt("customer_id"));
                        c.setFirstName(rs.getString("first_name"));
                        c.setLastName(rs.getString("last_name"));
                        c.setEmail(rs.getString("email"));
                        c.setContactNo(rs.getString("contact_no"));
                        c.setUsername(rs.getString("username"));
                        c.setPassword(rs.getString("password"));
                        c.setAddedDate(rs.getDate("added_date"));
                        c.setStatus(rs.getBoolean("status"));

                    }
                    return c;
                }
            });
}

From source file:com.havoc.hotel.admin.dao.impl.CustomerDAOImpl.java

@Override
public Customer getByUsername(String username) throws SQLException {
    return jdbcTemplate.query(SQLConstant.CUSTOMER_GETBYUSER, new Object[] { username },
            new ResultSetExtractor<Customer>() {

                @Override/*w w w.java 2 s .c o m*/
                public Customer extractData(ResultSet rs) throws SQLException, DataAccessException {
                    Customer c = null;
                    if (rs.next()) {
                        c = new Customer();
                        c.setCustomerId(rs.getInt("customer_id"));
                        c.setFirstName(rs.getString("first_name"));
                        c.setLastName(rs.getString("last_name"));
                        c.setEmail(rs.getString("email"));
                        c.setContactNo(rs.getString("contact_no"));
                        c.setUsername(rs.getString("username"));
                        c.setPassword(rs.getString("password"));
                        c.setAddedDate(rs.getDate("added_date"));
                        c.setStatus(rs.getBoolean("status"));

                    }
                    return c;

                }
            });
}