Example usage for java.sql PreparedStatement setFloat

List of usage examples for java.sql PreparedStatement setFloat

Introduction

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

Prototype

void setFloat(int parameterIndex, float x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java float value.

Usage

From source file:edu.cmu.lti.oaqa.openqa.hello.eval.passage.PassageMAPEvalPersistenceProvider.java

@Override
public void insertPartialCounts(final Key key, final String sequenceId, final PassageMAPCounts counts)
        throws SQLException {
    final String eName = getClass().getSimpleName();
    String insert = getInsertPassageAggregates();
    final Trace trace = key.getTrace();
    DataStoreImpl.getInstance().jdbcTemplate().update(insert, new PreparedStatementSetter() {
        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setString(1, key.getExperiment());
            ps.setString(2, trace.getTrace());
            ps.setString(3, eName);//from   www .java  2  s .c  o  m
            ps.setFloat(4, counts.getDocavep());
            ps.setFloat(5, counts.getPsgavep());
            ps.setFloat(6, counts.getAspavep());
            ps.setFloat(7, counts.getCount());
            ps.setString(8, sequenceId);
            ps.setInt(9, key.getStage());
            ps.setString(10, trace.getTraceHash());
        }
    });
}

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

public void setPreparedStatementValue(int iindex, String value, PreparedStatement pstmt, AbsDatabaseType dbtype)
        throws SQLException {
    log.debug("setFloat(" + iindex + "," + value + ")");
    Object objTmp = label2value(value);
    if (objTmp == null) {
        pstmt.setObject(iindex, null, java.sql.Types.FLOAT);
    } else {//www .jav a 2s .com
        pstmt.setFloat(iindex, (Float) objTmp);
    }
}

From source file:org.etudes.jforum.dao.generic.GenericGradeDAO.java

/**
 * {@inheritDoc}/*from   ww  w .j a va2 s  . c  o m*/
 */
public void updateForumGrade(Grade grade) throws Exception {
    PreparedStatement p = JForum.getConnection()
            .prepareStatement(SystemGlobals.getSql("GradeModel.updateForumGrade"));

    p.setFloat(1, grade.getPoints());
    p.setInt(2, grade.getType());
    p.setInt(3, grade.isAddToGradeBook() ? 1 : 0);
    if (grade.isMinimumPostsRequired()) {
        p.setInt(4, 1);
        p.setInt(5, grade.getMinimumPosts());
    } else {
        p.setInt(4, 0);
        p.setInt(5, 0);
    }
    p.setInt(6, grade.getForumId());

    p.executeUpdate();
    p.close();
}

From source file:org.etudes.jforum.dao.generic.GenericGradeDAO.java

/**
 * {@inheritDoc}//from w ww.j  ava2 s. c o  m
 */
public void updateTopicGrade(Grade grade) throws Exception {
    PreparedStatement p = JForum.getConnection()
            .prepareStatement(SystemGlobals.getSql("GradeModel.updateTopicGrade"));

    p.setFloat(1, grade.getPoints());
    p.setInt(2, grade.getType());
    if (grade.isMinimumPostsRequired()) {
        p.setInt(3, 1);
        p.setInt(4, grade.getMinimumPosts());
    } else {
        p.setInt(3, 0);
        p.setInt(4, 0);
    }
    p.setInt(5, grade.getForumId());
    p.setInt(6, grade.getTopicId());

    p.executeUpdate();
    p.close();
}

From source file:org.etudes.jforum.dao.generic.GenericGradeDAO.java

/**
 * {@inheritDoc}/*from   w w  w. j a  va 2s . c  o m*/
 */
public void updateCategoriesGrade(Grade grade) throws Exception {
    PreparedStatement p = JForum.getConnection()
            .prepareStatement(SystemGlobals.getSql("GradeModel.updateCategoryGrade"));

    p.setFloat(1, grade.getPoints());

    if (grade.isMinimumPostsRequired()) {
        p.setInt(2, 1);
        p.setInt(3, grade.getMinimumPosts());
    } else {
        p.setInt(2, 0);
        p.setInt(3, 0);
    }
    p.setInt(4, grade.getCategoryId());

    p.executeUpdate();
    p.close();

}

From source file:org.plista.kornakapi.core.storage.MySqlMaxPersistentStorage.java

@Override
public void batchSetPreferences(Iterator<Preference> preferences, int batchSize) throws IOException {
    Connection conn = null;/*from  w  ww.  jav a 2 s.c  om*/
    PreparedStatement stmt = null;

    try {
        conn = dataSource.getConnection();
        stmt = conn.prepareStatement(IMPORT_QUERY_MAX);

        int recordsQueued = 0;

        while (preferences.hasNext()) {
            Preference preference = preferences.next();
            stmt.setLong(1, preference.getUserID());
            stmt.setLong(2, preference.getItemID());
            stmt.setFloat(3, preference.getValue());
            stmt.addBatch();

            if (++recordsQueued % batchSize == 0) {
                stmt.executeBatch();
                log.info("imported {} records in batch", recordsQueued);
            }
        }

        if (recordsQueued % batchSize != 0) {
            stmt.executeBatch();
            log.info("imported {} records in batch. done.", recordsQueued);
        }

    } catch (SQLException e) {
        throw new IOException(e);
    } finally {
        IOUtils.quietClose(stmt);
        IOUtils.quietClose(conn);
    }
}

From source file:org.silverpeas.components.projectmanager.model.ProjectManagerDAO.java

private static int executeQueryAddTask(Connection con, TaskDetail task, StringBuilder insertStatement)
        throws SQLException {

    PreparedStatement prepStmt = null;
    int id = -1;/*  w ww. ja  v a2  s  .  com*/
    try {
        prepStmt = con.prepareStatement(insertStatement.toString());

        id = DBUtil.getNextId(PROJECTMANAGER_TASKS_TABLENAME, "id");
        prepStmt.setInt(1, id);
        prepStmt.setInt(2, task.getMereId());
        if (task.getMereId() == -1) {
            prepStmt.setInt(3, 0);
        } else {
            prepStmt.setInt(3, getChrono(con, task.getInstanceId()));
        }
        prepStmt.setString(4, task.getNom());
        prepStmt.setString(5, task.getDescription());
        prepStmt.setInt(6, task.getOrganisateurId());
        prepStmt.setInt(7, task.getResponsableId());
        prepStmt.setFloat(8, task.getCharge());
        prepStmt.setFloat(9, task.getConsomme());
        prepStmt.setFloat(10, task.getRaf());
        prepStmt.setInt(11, task.getAvancement());
        prepStmt.setInt(12, task.getStatut());
        prepStmt.setString(13, DateUtil.date2SQLDate(task.getDateDebut()));
        if (task.getDateFin() != null) {
            prepStmt.setString(14, DateUtil.date2SQLDate(task.getDateFin()));
        } else {
            prepStmt.setString(14, "9999/99/99");
        }
        prepStmt.setString(15, task.getCodeProjet());
        prepStmt.setString(16, task.getDescriptionProjet());
        prepStmt.setInt(17, task.getEstDecomposee());
        prepStmt.setString(18, task.getInstanceId());
        prepStmt.setString(19, task.getPath() + id + "/");
        prepStmt.setInt(20, task.getPreviousTaskId());

        prepStmt.executeUpdate();
    } finally {
        DBUtil.close(prepStmt);
    }
    return id;
}

From source file:com.climate.oada.dao.impl.PostGISResourceDAO.java

@Override
public boolean insert(LandUnit lu) {
    boolean retval = false;
    Connection conn = null;/*from  w w w.  j av a 2  s  .  c  om*/
    try {
        conn = dataSource.getConnection();
        PreparedStatement ps = conn.prepareStatement(INSERT_LANDUNIT_SQL);
        ps.setLong(ID_INDEX, lu.getUnitId());
        ps.setLong(USER_ID_INDEX, lu.getUserId());
        ps.setString(NAME_INDEX, lu.getName());
        ps.setString(FARM_NAME_INDEX, lu.getFarmName());
        ps.setString(CLIENT_NAME_INDEX, lu.getClientName());
        ps.setFloat(ACRES_INDEX, lu.getAcres());
        ps.setString(SOURCE_INDEX, lu.getSource());
        ps.setString(OTHER_PROPS_INDEX, null);
        ps.setString(GEOM_INDEX, lu.getWktBoundary());
        ps.executeUpdate();
        ps.close();
        retval = true;
    } catch (SQLException e) {
        LOG.error("Landunit insert failed " + lu.toString());
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                LOG.error("JDBC Connection Close Failed " + e.getMessage());
            }
        }
    }
    return retval;

}

From source file:com.pivotal.gfxd.demo.loader.Loader.java

public void insertBatch(final List<String[]> lines, final long timestamp) {
    String sql = "insert into raw_sensor (id, timestamp, value, property, plug_id, household_id, house_id, weekday, time_slice) values (?,?,?,?,?,?,?,?,?)";
    final Calendar cal = Calendar.getInstance();

    getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() {
        @Override/*from  ww w . ja va  2  s.  c o  m*/
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            final String[] split = lines.get(i);
            int plugId = Integer.parseInt(split[4]);
            int householdId = Integer.parseInt(split[5]);
            int houseId = Integer.parseInt(split[6]);

            ps.setLong(1, Long.parseLong(split[0]));
            ps.setLong(2, timestamp);
            float value = Float.parseFloat(split[2]);
            ps.setFloat(3, value + value * disturbance);
            ps.setInt(4, Integer.parseInt(split[3]));
            ps.setInt(5, computePlugId(plugId, householdId, houseId));
            ps.setInt(6, householdId);
            ps.setInt(7, houseId);

            cal.setTimeInMillis(timestamp * 1000L);
            int weekDay = cal.get(Calendar.DAY_OF_WEEK);
            int timeSlice = (cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE))
                    / MINUTES_PER_INTERVAL;

            ps.setInt(8, weekDay); // weekday
            ps.setInt(9, timeSlice); // time_slice
        }

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

    cal.setTimeInMillis(timestamp * 1000L);
    int weekDay = cal.get(Calendar.DAY_OF_WEEK);
    int timeSlice = (cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE)) / MINUTES_PER_INTERVAL;

    LOG.debug("rows=" + lines.size() + " weekday=" + weekDay + " slice=" + timeSlice + " stamp=" + timestamp
            + " now=" + (int) (System.currentTimeMillis() / 1000));

    rowsInserted += lines.size();
}