Example usage for java.sql PreparedStatement setDate

List of usage examples for java.sql PreparedStatement setDate

Introduction

In this page you can find the example usage for java.sql PreparedStatement setDate.

Prototype

void setDate(int parameterIndex, java.sql.Date x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given java.sql.Date value using the default time zone of the virtual machine that is running the application.

Usage

From source file:biblivre3.acquisition.quotation.QuotationDAO.java

public boolean updateQuotation(QuotationDTO dto) {
    Connection conInsert = null;//from  w ww .j ava 2 s .  c  om
    try {
        conInsert = getDataSource().getConnection();
        final String sqlInsert = " UPDATE acquisition_quotation " + " SET "
                + " serial_supplier=?, response_date=?, " + " expiration_date=?, delivery_time=?, "
                + " responsable=?, obs=? " + " WHERE serial_quotation = ?; ";

        PreparedStatement pstInsert = conInsert.prepareStatement(sqlInsert);
        pstInsert.setInt(1, dto.getSerialSupplier());
        pstInsert.setDate(2, new java.sql.Date(dto.getResponseDate().getTime()));
        pstInsert.setDate(3, new java.sql.Date(dto.getExpirationDate().getTime()));
        pstInsert.setInt(4, dto.getDeliveryTime());
        pstInsert.setString(5, dto.getResponsible());
        pstInsert.setString(6, dto.getObs());
        pstInsert.setInt(7, dto.getSerial());
        return pstInsert.executeUpdate() > 0;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new DAOException(e.getMessage());
    } finally {
        closeConnection(conInsert);
    }
}

From source file:Controllers.myAppointmentController.java

public Appointment[] fetchAppointments(java.sql.Date date) {

    Appointment[] Appoint = null;//from  ww  w.j a  v  a  2 s.c om

    try {
        Context ctx = new InitialContext();
        DataSource ds = (DataSource) ctx.lookup("jdbc/medicalCareDataSource");
        connection = ds.getConnection();

        PreparedStatement pstmt = connection
                .prepareStatement("SELECT appointments.message," + "FROM appointments JOIN accounts\n"
                        + "WHERE appointments.date = ? and email=${sessionScope.user};");

        pstmt.setDate(1, date);

        ResultSet resultSet = pstmt.executeQuery();

        List<Appointment> appointmentsList = new ArrayList<Appointment>();
        while (resultSet.next()) {
            Appointment appoint = new Appointment();
            appoint.setAppointmentId(resultSet.getInt("appointmentId"));
            appoint.setMessage(resultSet.getString("message"));
            appoint.setDepartmentId(resultSet.getInt("depoartmentId"));

            appointmentsList.add(appoint);
        }

        Appoint = new Appointment[appointmentsList.size()];
        Appoint = appointmentsList.toArray(Appoint);

        pstmt.close();

    } catch (NamingException ex) {
        Logger.getLogger(AppointmentController.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Logger.getLogger(AppointmentController.class.getName()).log(Level.SEVERE, null, ex);
    }

    return Appoint;
}

From source file:com.squid.core.jdbc.vendor.sqlserver.SQLServerJDBCDataFormatter.java

@Override
public void setData(PreparedStatement pstmt, int position, Object data, int colType, int size, int precision)
        throws SQLException, NullPointerException {
    // TODO Auto-generated method stub
    if (colType == Types.DATE || colType == Types.TIMESTAMP || colType == Types.TIME) {
        if (data != null) {
            pstmt.setDate(position, new java.sql.Date(((java.util.Date) data).getTime()));
        } else {//from   ww  w.j a  v a  2s .  c  o m
            pstmt.setDate(position, null);
        }
    } else {
        super.setData(pstmt, position, data, colType, size, precision);
    }
}

From source file:org.forumj.dbextreme.db.dao.FJSubscribeDao.java

public void create(IFJSubscribe subscribe) throws ConfigurationException, SQLException, IOException {
    String query = getCreateSubscribeQuery();
    Connection conn = null;/*w w  w .  j  a v  a  2  s .  c  o  m*/
    PreparedStatement st = null;
    try {
        conn = getConnection();
        st = conn.prepareStatement(query);
        st.setLong(1, subscribe.getUser().getId());
        st.setLong(2, subscribe.getTitleId());
        st.setDate(3, new java.sql.Date(subscribe.getStart().getTime()));
        st.setLong(4, subscribe.getKey());
        st.setInt(5, subscribe.getType());
        st.executeUpdate();
    } finally {
        readFinally(conn, st);
    }
}

From source file:com.apress.prospringintegration.springenterprise.stocks.dao.jdbc.JdbcTemplateStockDao.java

@Override
public void update(final Stock stock) {
    jdbcTemplate.update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
            String sql = "UPDATE STOCKS SET SYMBOL = ?, INVENTORY_CODE = ?, "
                    + "PRICE_PER_SHARE = ?, QUANTITY_AVAILABLE = ?, "
                    + "EXCHANGE_ID = ?, PURCHASE_DATE = ? where ID = ?";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1, stock.getSymbol());
            ps.setString(2, stock.getInventoryCode());
            ps.setFloat(3, stock.getSharePrice());
            ps.setFloat(4, stock.getQuantityAvailable());
            ps.setString(5, stock.getExchangeId());
            ps.setDate(6, new java.sql.Date(stock.getPurchaseDate().getTime()));
            ps.setInt(7, stock.getId());
            return ps;
        }//  ww  w. ja  v  a 2  s .c  om
    });
}

From source file:com.microsoftopentechnologies.azchat.web.dao.PreferenceMetadataDAOImpl.java

/**
 * This method used to generate prepare statement object from given
 * preferenceMetadataEntity object.//ww w.  j ava2 s  .  com
 * 
 * @param preparedStatement
 * @param preferenceMetadataEntity
 * @return
 * @throws SQLException
 */
public PreparedStatement generatePreparedStatement(PreparedStatement preparedStatement,
        PreferenceMetadataEntity preferenceMetadataEntity) throws SQLException {
    preparedStatement.setString(1, preferenceMetadataEntity.getPreferenceDesc());
    preparedStatement.setDate(2, new java.sql.Date(preferenceMetadataEntity.getDateCreated().getTime()));
    preparedStatement.setDate(3, new java.sql.Date(preferenceMetadataEntity.getDateCreated().getTime()));
    preparedStatement.setDate(4, new java.sql.Date(preferenceMetadataEntity.getDateCreated().getTime()));
    preparedStatement.setDate(5, new java.sql.Date(preferenceMetadataEntity.getDateCreated().getTime()));
    return preparedStatement;
}

From source file:org.obiba.onyx.jade.instrument.reichert.OraInstrumentRunner.java

/**
 * Retrieve participant data from the database and write them in the patient scan database
 * /* w  ww  .j  a va  2  s .c om*/
 * @throws Exception
 */
private void initializeParticipantData() {
    log.info("initializing participant Data");

    jdbc.update("insert into Patients ( Name, BirthDate, Sex, GroupID, ID, RaceID ) values( ?, ?, ?, ?, ?, ? )",
            new PreparedStatementSetter() {

                @Override
                public void setValues(PreparedStatement ps) throws SQLException {
                    ps.setString(1, instrumentExecutionService.getParticipantLastName() + ", "
                            + instrumentExecutionService.getParticipantFirstName());
                    ps.setDate(2,
                            new java.sql.Date(instrumentExecutionService.getParticipantBirthDate().getTime()));
                    ps.setBoolean(3, instrumentExecutionService.getParticipantGender().startsWith("M"));
                    ps.setInt(4, 2);
                    ps.setInt(5, id);
                    ps.setInt(6, 1);
                }
            });
}

From source file:biblivre3.acquisition.order.BuyOrderDAO.java

public boolean insertBuyOrder(BuyOrderDTO dto) {
    Connection conInsert = null;//from  w ww .jav  a  2 s .c  o  m
    try {
        conInsert = getDataSource().getConnection();
        final String sqlInsert = " INSERT INTO acquisition_order (serial_quotation, order_date, "
                + " responsable, obs, status, invoice_number, "
                + " receipt_date, total_value, delivered_quantity, " + " terms_of_payment, deadline_date) "
                + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); ";
        PreparedStatement pstInsert = conInsert.prepareStatement(sqlInsert);
        pstInsert.setInt(1, dto.getSerialQuotation());
        pstInsert.setDate(2, new java.sql.Date(dto.getOrderDate().getTime()));
        pstInsert.setString(3, dto.getResponsible());
        pstInsert.setString(4, dto.getObs());
        pstInsert.setString(5, dto.getStatus());
        pstInsert.setString(6, dto.getInvoiceNumber());

        Date receiptDate = dto.getReceiptDate();
        if (receiptDate != null) {
            pstInsert.setDate(7, new java.sql.Date(receiptDate.getTime()));
        } else {
            pstInsert.setNull(7, java.sql.Types.DATE);
        }

        Float totalValue = dto.getTotalValue();
        if (totalValue != null) {
            pstInsert.setFloat(8, totalValue);
        } else {
            pstInsert.setNull(8, java.sql.Types.FLOAT);
        }

        Integer deliveryQuantity = dto.getDeliveredQuantity();
        if (deliveryQuantity != null) {
            pstInsert.setInt(9, deliveryQuantity);
        } else {
            pstInsert.setNull(9, java.sql.Types.INTEGER);
        }

        pstInsert.setString(10, dto.getTermsOfPayment());
        pstInsert.setDate(11, new java.sql.Date(dto.getDeadlineDate().getTime()));
        return pstInsert.executeUpdate() > 0;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new DAOException(e.getMessage());
    } finally {
        closeConnection(conInsert);
    }
}

From source file:biblivre3.acquisition.order.BuyOrderDAO.java

public boolean updateBuyOrder(BuyOrderDTO dto) {
    Connection conInsert = null;//  w  w  w .  j a  v a 2  s.c  o  m
    try {
        conInsert = getDataSource().getConnection();
        final String sqlInsert = " UPDATE acquisition_order " + " SET serial_quotation = ?, order_date = ?, "
                + " responsable = ?, obs = ?, status = ?, "
                + " invoice_number = ?, receipt_date = ?, total_value = ?, "
                + " delivered_quantity = ?, terms_of_payment = ?, deadline_date=? "
                + " WHERE serial_order = ?;";

        PreparedStatement pstInsert = conInsert.prepareStatement(sqlInsert);
        pstInsert.setInt(1, dto.getSerialQuotation());
        pstInsert.setDate(2, new java.sql.Date(dto.getOrderDate().getTime()));
        pstInsert.setString(3, dto.getResponsible());
        pstInsert.setString(4, dto.getObs());
        pstInsert.setString(5, dto.getStatus() != null && dto.getStatus().equals("1") ? "1" : "0");
        pstInsert.setString(6, dto.getInvoiceNumber());

        Date receiptDate = dto.getReceiptDate();
        if (receiptDate != null) {
            pstInsert.setDate(7, new java.sql.Date(receiptDate.getTime()));
        } else {
            pstInsert.setNull(7, java.sql.Types.DATE);
        }

        Float totalValue = dto.getTotalValue();
        if (totalValue != null) {
            pstInsert.setFloat(8, totalValue);
        } else {
            pstInsert.setNull(8, java.sql.Types.FLOAT);
        }

        Integer deliveryQuantity = dto.getDeliveredQuantity();
        if (deliveryQuantity != null) {
            pstInsert.setInt(9, deliveryQuantity);
        } else {
            pstInsert.setNull(9, java.sql.Types.INTEGER);
        }

        pstInsert.setString(10, dto.getTermsOfPayment());
        pstInsert.setDate(11, new java.sql.Date(dto.getDeadlineDate().getTime()));
        pstInsert.setInt(12, dto.getSerial());
        return pstInsert.executeUpdate() > 0;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new DAOException(e.getMessage());
    } finally {
        closeConnection(conInsert);
    }
}

From source file:org.obiba.onyx.jade.instrument.gehealthcare.AchillesExpressInstrumentRunner.java

public void setParticipantData() {

    achillesExpressDb.update(//  w ww.j  ava2  s . c o  m
            "insert into Patients ( Chart_Num, FName, LName, DOB, Sex, Foot ) values( ?, ?, ?, ?, ?, ? )",
            new PreparedStatementSetter() {
                public void setValues(PreparedStatement ps) throws SQLException {
                    ps.setString(1, participantID);
                    ps.setString(2, participantFirstName);
                    ps.setString(3, participantLastName);
                    ps.setDate(4, new java.sql.Date(participantBirthDate.getTime()));

                    if (participantGender.equals("MALE")) {
                        ps.setString(5, "M");
                    } else {
                        ps.setString(5, "F");
                    }

                    if (instrumentExecutionService.getInputParameterValue("INPUT_FOOT_SCANNED")
                            .getValueAsString().equals("LEFT_FOOT")) {
                        ps.setString(6, "L");
                    } else {
                        ps.setString(6, "R");
                    }
                }
            });

}