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:org.silverpeas.components.projectmanager.model.ProjectManagerDAO.java

public static void updateTask(Connection con, TaskDetail task) throws SQLException, UtilException {
    StringBuilder updateQuery = new StringBuilder();
    updateQuery.append("UPDATE ").append(PROJECTMANAGER_TASKS_TABLENAME);
    updateQuery.append(" SET nom = ? , description = ? , responsableId = ? , charge = ? , ");
    updateQuery.append("consomme = ? , raf = ? , avancement = ? , statut = ? , dateDebut = ? , ");
    updateQuery.append("dateFin = ? , previousId = ? WHERE id = ? ");

    PreparedStatement prepStmt = null;

    try {//from   ww w . j av a2  s  . c om
        prepStmt = con.prepareStatement(updateQuery.toString());
        prepStmt.setString(1, task.getNom());
        prepStmt.setString(2, task.getDescription());
        prepStmt.setInt(3, task.getResponsableId());
        prepStmt.setFloat(4, task.getCharge());
        prepStmt.setFloat(5, task.getConsomme());
        prepStmt.setFloat(6, task.getRaf());
        prepStmt.setInt(7, task.getAvancement());
        prepStmt.setInt(8, task.getStatut());
        prepStmt.setString(9, DateUtil.date2SQLDate(task.getDateDebut()));
        if (task.getDateFin() != null) {
            prepStmt.setString(10, DateUtil.date2SQLDate(task.getDateFin()));
        } else {
            prepStmt.setString(10, "9999/99/99");
        }
        prepStmt.setInt(11, task.getPreviousTaskId());

        prepStmt.setInt(12, task.getId());

        prepStmt.executeUpdate();

        // mise  jour des resources
        deleteAllResources(con, task.getId(), task.getInstanceId());

        if (task.getResources() != null) {
            Iterator<TaskResourceDetail> it = task.getResources().iterator();
            while (it.hasNext()) {
                TaskResourceDetail resource = it.next();
                resource.setTaskId(task.getId());
                resource.setInstanceId(task.getInstanceId());
                addResource(con, resource);
            }
        }
    } finally {
        DBUtil.close(prepStmt);
    }
}

From source file:org.castor.jdo.engine.SQLTypeInfos.java

/**
 * Set given value on given PreparedStatement at given index with given SQL type.
 * //from  w  w  w.  ja va  2  s  .  c o m
 * @param stmt The PreparedStatement to set value on.
 * @param index The index of the value in the PreparedStatement.
 * @param value The value to set.
 * @param sqlType The SQL type of the value.
 */
public static void setValue(final PreparedStatement stmt, final int index, final Object value,
        final int sqlType) {
    try {
        if (value == null) {
            stmt.setNull(index, sqlType);
        } else {
            // Special processing for BLOB and CLOB types, because they are mapped
            // by Castor to java.io.InputStream and java.io.Reader, respectively,
            // while JDBC driver expects java.sql.Blob and java.sql.Clob.
            switch (sqlType) {
            case Types.FLOAT:
            case Types.DOUBLE:
                stmt.setDouble(index, ((Double) value).doubleValue());
                break;
            case Types.REAL:
                stmt.setFloat(index, ((Float) value).floatValue());
                break;
            case Types.TIME:
                final Time time = value instanceof java.util.Date ? new Time(((java.util.Date) value).getTime())
                        : null;
                stmt.setTime(index, time != null ? time : (Time) value, getCalendar());
                break;
            case Types.DATE:
                final Date date = value instanceof java.util.Date ? new Date(((java.util.Date) value).getTime())
                        : null;
                stmt.setDate(index, date != null ? date : (Date) value);
                break;
            case Types.TIMESTAMP:
                final Timestamp timestamp = value instanceof java.util.Date
                        ? new Timestamp(((java.util.Date) value).getTime())
                        : null;
                stmt.setTimestamp(index, timestamp != null ? timestamp : (Timestamp) value, getCalendar());
                break;
            case Types.BLOB:
                try {
                    InputStream stream;
                    if (value instanceof byte[]) {
                        stream = new ByteArrayInputStream((byte[]) value);
                    } else {
                        stream = (InputStream) value;
                    }
                    stmt.setBinaryStream(index, stream, stream.available());
                } catch (IOException ex) {
                    throw new SQLException(ex.toString());
                }
                break;
            case Types.CLOB:
                if (value instanceof String) {
                    stmt.setCharacterStream(index, new StringReader((String) value),
                            Math.min(((String) value).length(), Integer.MAX_VALUE));
                } else {
                    stmt.setCharacterStream(index, ((Clob) value).getCharacterStream(),
                            (int) Math.min(((Clob) value).length(), Integer.MAX_VALUE));
                }
                break;
            default:
                stmt.setObject(index, value, sqlType);
                break;
            }
        }
    } catch (SQLException ex) {
        LOG.error("Unexpected SQL exception: ", ex);
    }
}

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

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());/*from w  w w.j av  a  2 s.c o m*/
    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;
}

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

public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
    String sql = "INSERT INTO " + "STOCKS (SYMBOL, INVENTORY_CODE, PRICE_PER_SHARE,"
            + "QUANTITY_AVAILABLE, EXCHANGE_ID, PURCHASE_DATE) " + "VALUES (?, ?, ?, ?, ?, ?)";
    PreparedStatement ps = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);

    ps.setString(1, stock.getSymbol());//from w  ww.  jav  a 2s  .c  om
    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()));
    return ps;
}

From source file:org.apache.phoenix.util.TestUtil.java

/**
 * @param conn/* w ww.ja  v a  2  s.  c o  m*/
 *            connection to be used
 * @param sortOrder
 *            sort order of column contain input values
 * @param id
 *            id of the row being inserted
 * @param input
 *            input to be inserted
 */
public static void upsertRow(Connection conn, String tableName, String sortOrder, int id, Object input)
        throws SQLException {
    String dml = String.format("UPSERT INTO " + tableName + "_%s VALUES(?,?)", sortOrder);
    PreparedStatement stmt = conn.prepareStatement(dml);
    stmt.setInt(1, id);
    if (input instanceof String)
        stmt.setString(2, (String) input);
    else if (input instanceof Integer)
        stmt.setInt(2, (Integer) input);
    else if (input instanceof Double)
        stmt.setDouble(2, (Double) input);
    else if (input instanceof Float)
        stmt.setFloat(2, (Float) input);
    else if (input instanceof Boolean)
        stmt.setBoolean(2, (Boolean) input);
    else if (input instanceof Long)
        stmt.setLong(2, (Long) input);
    else
        throw new UnsupportedOperationException("" + input.getClass() + " is not supported by upsertRow");
    stmt.execute();
    conn.commit();
}

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;
        }// w w w .  java  2 s . c  om
    });
}

From source file:com.senior.g40.service.AccidentService.java

public boolean saveAccident(Accident acc) {
    try {/*from   w w  w  .  jav  a2  s .c o  m*/
        Connection conn = ConnectionBuilder.getConnection();
        String sqlCmd = "INSERT INTO `accident` "
                + "(`userId`, `date`, `time`, `latitude`, `longtitude`, `accCode`, `forceDetect`, `speedDetect`) "
                + "VALUES " + "(?, ?, ?, ?, ?, ?, ?, ?);";
        PreparedStatement pstm = conn.prepareStatement(sqlCmd);
        pstm.setLong(1, acc.getUserId());
        pstm.setDate(2, acc.getDate());
        pstm.setString(3, acc.getTime());
        pstm.setFloat(4, acc.getLatitude());
        pstm.setFloat(5, acc.getLongtitude());
        pstm.setFloat(6, acc.getForceDetect());
        pstm.setFloat(7, acc.getSpeedDetect());
        pstm.setString(8, String.valueOf(acc.getAccCode()));
        if (pstm.executeUpdate() != 0) {
            conn.close();
            return true;
        }
    } catch (SQLException ex) {
        Logger.getLogger(AccidentService.class.getName()).log(Level.SEVERE, null, ex);
    }
    return false;
}

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

@Override
public void setPreference(long userID, long itemID, float value) throws IOException {
    Connection conn = null;/* ww w . ja va 2s  .  co  m*/
    PreparedStatement stmt = null;
    try {
        conn = dataSource.getConnection();
        stmt = conn.prepareStatement(IMPORT_QUERY_MAX);
        stmt.setLong(1, userID);
        stmt.setLong(2, itemID);
        stmt.setFloat(3, value);
        stmt.execute();
    } catch (SQLException e) {
        throw new IOException(e);
    } finally {
        IOUtils.quietClose(stmt);
        IOUtils.quietClose(conn);
    }
}

From source file:com.l2jfree.gameserver.model.entity.faction.Faction.java

private void updateDB() {
    Connection con = null;//from  w w  w . jav a  2s.  co  m
    try {
        PreparedStatement statement;

        con = L2DatabaseFactory.getInstance().getConnection(con);

        statement = con.prepareStatement("update factions set points = ? where id = ?");
        statement.setFloat(1, _points);
        statement.setInt(2, _Id);
        statement.execute();
        statement.close();
    } catch (Exception e) {
        _log.warn("Exception: Faction.load(): " + e.getMessage(), e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

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

@Override
public void insertMAPMeasureEval(final Key key, final String eName, final PassageMAPEvaluationData eval)
        throws SQLException {
    String insert = getInsertMAPMeasureEval();
    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);//  w  w  w .  j  a  va  2s  .  com
            ps.setFloat(4, eval.getDocMap());
            ps.setFloat(5, eval.getPsgMap());
            ps.setFloat(6, eval.getAspMap());
            ps.setFloat(7, eval.getCount());
            ps.setInt(8, key.getStage());
            ps.setString(9, trace.getTraceHash());
        }
    });
}