Example usage for java.sql PreparedStatement setDouble

List of usage examples for java.sql PreparedStatement setDouble

Introduction

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

Prototype

void setDouble(int parameterIndex, double x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java double value.

Usage

From source file:com.github.viktornar.dao.ExtentDao.java

public void create(Extent extent) {
    String sql = format("INSERT INTO EXTENT (%s) VALUES (%s)", EXTENT_COLUMNS, questionMarks(EXTENT_COLUMNS));

    KeyHolder keyHolder = new GeneratedKeyHolder();

    getJdbcTemplate().update(connection -> {
        PreparedStatement ps = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        ps.setDouble(1, extent.getXmin());
        ps.setDouble(2, extent.getYmin());
        ps.setDouble(3, extent.getXmax());
        ps.setDouble(4, extent.getYmax());
        return ps;
    }, keyHolder);/*  w ww . j av  a2s. c o  m*/

    extent.setId((Integer) keyHolder.getKey());
}

From source file:com.app.dao.SearchQueryDAO.java

private static void _populateUpdateSearchQueryPreparedStatement(PreparedStatement preparedStatement,
        SearchQuery searchQuery, int userId) throws SQLException {

    preparedStatement.setString(1, searchQuery.getKeywords());
    preparedStatement.setString(2, searchQuery.getCategoryId());
    preparedStatement.setString(3, searchQuery.getSubcategoryId());
    preparedStatement.setBoolean(4, searchQuery.isSearchDescription());
    preparedStatement.setBoolean(5, searchQuery.isFreeShippingOnly());
    preparedStatement.setBoolean(6, searchQuery.isNewCondition());
    preparedStatement.setBoolean(7, searchQuery.isUsedCondition());
    preparedStatement.setBoolean(8, searchQuery.isUnspecifiedCondition());
    preparedStatement.setBoolean(9, searchQuery.isAuctionListing());
    preparedStatement.setBoolean(10, searchQuery.isFixedPriceListing());
    preparedStatement.setDouble(11, searchQuery.getMaxPrice());
    preparedStatement.setDouble(12, searchQuery.getMinPrice());
    preparedStatement.setString(13, searchQuery.getGlobalId());
    preparedStatement.setBoolean(14, searchQuery.isActive());
    preparedStatement.setInt(15, searchQuery.getSearchQueryId());
    preparedStatement.setInt(16, userId);
}

From source file:org.mskcc.cbio.cgds.dao.DaoGistic.java

public static void addGistic(Gistic gistic) throws DaoException, validationException {
    if (gistic == null) {
        throw new DaoException("Given a null gistic object");
    }/*www.j a v a2  s.  c o  m*/

    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;

    ValidateGistic.validateBean(gistic);

    try {
        con = JdbcUtil.getDbConnection(DaoGistic.class);
        // insert into SQL gistic table
        pstmt = con.prepareStatement("INSERT INTO gistic (`CANCER_STUDY_ID`," + "`CHROMOSOME`, "
                + "`CYTOBAND`, " + "`WIDE_PEAK_START`, " + "`WIDE_PEAK_END`, " + "`Q_VALUE`, " + "`AMP`) "
                + "VALUES (?,?,?,?,?,?,?)", Statement.RETURN_GENERATED_KEYS);

        pstmt.setInt(1, gistic.getCancerStudyId());
        pstmt.setInt(2, gistic.getChromosome());
        pstmt.setString(3, gistic.getCytoband());
        pstmt.setInt(4, gistic.getPeakStart());
        pstmt.setInt(5, gistic.getPeakEnd());
        pstmt.setDouble(6, gistic.getqValue());
        pstmt.setBoolean(7, gistic.getAmp());
        pstmt.executeUpdate();

        // insert into SQL gistic_to_gene table
        rs = pstmt.getGeneratedKeys();
        if (rs.next()) {
            int autoId = rs.getInt(1);
            gistic.setInternalId(autoId);
        }
        addGisticGenes(gistic, con);

    } catch (SQLException e) {
        throw new DaoException(e);
    } finally {
        JdbcUtil.closeAll(DaoGistic.class, con, pstmt, rs);
    }
}

From source file:at.alladin.rmbt.db.fields.DoubleField.java

@Override
public void getField(final PreparedStatement ps, final int idx) throws SQLException {
    if (value == null)
        ps.setNull(idx, Types.DOUBLE);
    else//from  w w w  .j a va 2s  . c o  m
        ps.setDouble(idx, value);
}

From source file:com.app.dao.SearchQueryDAO.java

private static void _populateAddSearchQueryPreparedStatement(PreparedStatement preparedStatement,
        SearchQuery searchQuery) throws SQLException {

    preparedStatement.setInt(1, searchQuery.getUserId());
    preparedStatement.setString(2, searchQuery.getKeywords());
    preparedStatement.setString(3, searchQuery.getCategoryId());
    preparedStatement.setString(4, searchQuery.getSubcategoryId());
    preparedStatement.setBoolean(5, searchQuery.isSearchDescription());
    preparedStatement.setBoolean(6, searchQuery.isFreeShippingOnly());
    preparedStatement.setBoolean(7, searchQuery.isNewCondition());
    preparedStatement.setBoolean(8, searchQuery.isUsedCondition());
    preparedStatement.setBoolean(9, searchQuery.isUnspecifiedCondition());
    preparedStatement.setBoolean(10, searchQuery.isAuctionListing());
    preparedStatement.setBoolean(11, searchQuery.isFixedPriceListing());
    preparedStatement.setDouble(12, searchQuery.getMaxPrice());
    preparedStatement.setDouble(13, searchQuery.getMinPrice());
    preparedStatement.setString(14, searchQuery.getGlobalId());
    preparedStatement.setBoolean(15, searchQuery.isActive());
}

From source file:mitll.xdata.dataset.kiva.ingest.KivaIngest.java

public static int executePreparedStatement(PreparedStatement statement, List<String> types, List<String> values)
        throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
    try {/* w  w w  .  j a v a  2 s  .co m*/
        for (int i = 0; i < types.size(); i++) {
            String type = TYPE_TO_DB.get(types.get(i).toUpperCase());
            String value = values.get(i);
            if (value != null && value.trim().length() == 0) {
                value = null;
            }
            if (type.equalsIgnoreCase("INT")) {
                if (value == null) {
                    statement.setNull(i + 1, java.sql.Types.INTEGER);
                } else {
                    statement.setInt(i + 1, Integer.parseInt(value, 10));
                }
            } else if (type.equalsIgnoreCase("DOUBLE")) {
                if (value == null) {
                    statement.setNull(i + 1, java.sql.Types.DOUBLE);
                } else {
                    statement.setDouble(i + 1, Double.parseDouble(value));
                }
            } else if (type.equalsIgnoreCase("BOOLEAN")) {
                if (value == null) {
                    statement.setNull(i + 1, java.sql.Types.BOOLEAN);
                } else {
                    statement.setBoolean(i + 1, Boolean.parseBoolean(value));
                }
            } else if (type.equalsIgnoreCase("VARCHAR")) {
                statement.setString(i + 1, value);
            } else if (type.equalsIgnoreCase("TIMESTAMP")) {
                if (value == null) {
                    statement.setNull(i + 1, java.sql.Types.TIMESTAMP);
                } else {
                    statement.setTimestamp(i + 1, new Timestamp(sdf.parse(value).getTime()));
                }
            }
        }
    } catch (Throwable e) {
        System.out.println("types = " + types);
        System.out.println("values = " + values);
        System.out.println("types.size() = " + types.size());
        System.out.println("values.size() = " + values.size());
        e.printStackTrace();
        System.out.println(e.getMessage());
        throw new Exception(e);
    }
    return statement.executeUpdate();
}

From source file:com.thesoftwareguild.flightmaster.daos.RequestDaoJdbcImpl.java

@Override
@Transactional(propagation = Propagation.REQUIRED)
public List<Flight> addFlights(int requestId, List<Flight> flights) {
    if (flights != null && flights.size() > 0) {
        Date timeOfQuery = flights.get(0).getQueryTime();
        jdbcTemplate.update(SQL_ADD_REQUESTDATA_POINT, requestId, timeOfQuery);
        int requestDataId = jdbcTemplate.queryForObject(SQL_GET_LAST_ID, Integer.class);
        jdbcTemplate.batchUpdate(SQL_ADD_FLIGHT_DATA, new BatchPreparedStatementSetter() {

            @Override//w  ww . ja v  a 2  s.c om
            public void setValues(PreparedStatement ps, int i) throws SQLException {
                ps.setInt(1, requestDataId);
                ps.setDouble(2, flights.get(i).getPrice());
                ps.setString(3, flights.get(i).getCarrier());
            }

            @Override
            public int getBatchSize() {
                return flights.size();
            }
        });
        // Decrement queries_left to keep it consistant with in-memory representation
        jdbcTemplate.update(SQL_DECREMENT_QUERIESLEFT, requestId);
        // Get interval and set next execution time in database
        long interval = jdbcTemplate.queryForObject(SQL_GET_INTERVAL, Long.class, requestId);
        jdbcTemplate.update(SQL_UPDATE_NEXT_EXECUTION, (System.currentTimeMillis() + interval), requestId);
    }
    return flights;
}

From source file:jobimtext.thesaurus.distributional.DatabaseThesaurusDatastructure.java

public List<Order2> getExpansions(String key, double threshold) {
    try {//from  www . java2 s  . c om
        String sql = "SELECT word1, word2,count FROM " + tableOrder2
                + " WHERE word1 = ? and count > ? ORDER BY count desc";
        PreparedStatement ps = getDatabaseConnection().getConnection().prepareStatement(sql);
        ps.setString(1, key);
        ps.setDouble(2, threshold);
        return fillExpansions(ps);
    } catch (SQLException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.apromore.dao.jpa.FragmentDistanceRepositoryCustomImpl.java

/**
 * Save a distance calculation into the DB.
 * @param distances the array of details for the distance inserts.
 *///from  w  w w .  ja v  a 2 s .  c  o  m
@Override
public void persistDistance(final List<DistanceDO> distances) {
    String sql = "INSERT INTO fragment_distance (fragmentVersionId1, fragmentVersionId2, ged) VALUES (?,?,?)";

    jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            DistanceDO distanceDO = distances.get(i);
            ps.setInt(1, distanceDO.getFragmentId1());
            ps.setInt(2, distanceDO.getFragmentId2());
            ps.setDouble(3, distanceDO.getGed());
        }

        @Override
        public int getBatchSize() {
            return distances.size();
        }
    });
}

From source file:com.wabacus.system.datatype.DoubleType.java

public void setPreparedStatementValue(int iindex, String value, PreparedStatement pstmt, AbsDatabaseType dbtype)
        throws SQLException {
    log.debug("setDouble(" + iindex + "," + value + ")");
    Object objTmp = label2value(value);
    if (objTmp == null) {
        pstmt.setObject(iindex, null, java.sql.Types.DOUBLE);
    } else {/*from w w  w . jav a2 s .c o  m*/
        pstmt.setDouble(iindex, (Double) objTmp);
    }
}