Example usage for java.sql PreparedStatement setLong

List of usage examples for java.sql PreparedStatement setLong

Introduction

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

Prototype

void setLong(int parameterIndex, long x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java long value.

Usage

From source file:de.iritgo.aktario.jdbc.JDBCIDGenerator.java

/**
 * Allocate new ids.//w  w w.  j a va  2  s.  c o  m
 */
protected void allocateIds() {
    JDBCManager jdbcManager = (JDBCManager) Engine.instance().getManager("persist.JDBCManager");
    DataSource dataSource = jdbcManager.getDefaultDataSource();

    Connection connection = null;
    PreparedStatement stmt = null;

    try {
        connection = dataSource.getConnection();

        stmt = connection.prepareStatement("update IritgoProperties set value=? where name=?");
        stmt.setLong(1, id + chunk * step);
        stmt.setString(2, "persist.ids.nextvalue");
        stmt.execute();

        free = chunk;

        Log.logVerbose("persist", "JDBCIDGenerator", "Successfully allocated new ids (id=" + id + ")");
    } catch (Exception x) {
        Log.logFatal("persist", "JDBCIDGenerator", "Error while allocating new ids: " + x);
    } finally {
        DbUtils.closeQuietly(stmt);
        DbUtils.closeQuietly(connection);
    }
}

From source file:com.carfinance.module.peoplemanage.dao.PeopleManageDao.java

public void peopleroleDoEdit(final long edited_user_id, final long org_id, final String role_ids) {
    this.deleteUserOrgRole(org_id, edited_user_id);
    if (role_ids.length() > 0) {
        final String[] role_id = role_ids.split(",");
        String sql = "insert into user_role (user_id , role_id , org_id) values (?,?,?)";
        try {//from ww  w . ja va 2 s .com
            this.getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() {
                public void setValues(PreparedStatement ps, int i) throws SQLException {
                    ps.setLong(1, edited_user_id);
                    ps.setLong(2, Long.valueOf(role_id[i]));
                    ps.setLong(3, org_id);
                }

                public int getBatchSize() {
                    return role_id.length;//??labels.length
                }
            });
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
}

From source file:de.ingrid.importer.udk.strategy.v1.IDCStrategy1_0_5_fixCountryCodelist.java

private void updateSysList() throws Exception {
    if (log.isInfoEnabled()) {
        log.info("Updating sys_list...");
    }/*from   w  ww.j a  v  a  2s.c o m*/

    // ---------------------------------------------

    if (log.isInfoEnabled()) {
        log.info("Updating syslist " + UtilsCountryCodelist.COUNTRY_SYSLIST_ID + " Country ...");
    }

    // clean up, to guarantee no old values !
    sqlStr = "DELETE FROM sys_list where lst_id = " + UtilsCountryCodelist.COUNTRY_SYSLIST_ID;
    jdbc.executeUpdate(sqlStr);

    pSqlStr = "INSERT INTO sys_list (id, lst_id, entry_id, lang_id, name, maintainable, is_default) "
            + "VALUES ( ?, " + UtilsCountryCodelist.COUNTRY_SYSLIST_ID + ", ?, ?, ?, 0, ?)";

    PreparedStatement pS = jdbc.prepareStatement(pSqlStr);

    Iterator<Integer> itr = UtilsCountryCodelist.countryCodelist_de.keySet().iterator();
    while (itr.hasNext()) {
        Integer key = itr.next();

        // german version
        int cnt = 1;
        pS.setLong(cnt++, getNextId()); // id
        pS.setInt(cnt++, key); // entry_id
        pS.setString(cnt++, "de"); // lang_id
        pS.setString(cnt++, UtilsCountryCodelist.countryCodelist_de.get(key)); // name
        pS.setString(cnt++, (key.equals(UtilsCountryCodelist.COUNTRY_KEY_GERMANY)) ? "Y" : "N"); // is_default
        pS.executeUpdate();

        // english version
        cnt = 1;
        pS.setLong(cnt++, getNextId()); // id
        pS.setInt(cnt++, key); // entry_id
        pS.setString(cnt++, "en"); // lang_id
        pS.setString(cnt++, UtilsCountryCodelist.countryCodelist_en.get(key)); // name
        pS.setString(cnt++, (key.equals(UtilsCountryCodelist.COUNTRY_KEY_GBR)) ? "Y" : "N"); // is_default
        pS.executeUpdate();
    }

    pS.close();

    if (log.isInfoEnabled()) {
        log.info("Updating sys_list... done");
    }
}

From source file:com.hs.mail.imap.dao.MySqlMessageDao.java

private long addPhysicalMessage(final MailMessage message) {
    final String sql = "INSERT INTO physmessage (size, internaldate, subject, sentdate, fromaddr) VALUES(?, ?, ?, ?, ?)";
    final MessageHeader header = message.getHeader();
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcTemplate().update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
            PreparedStatement pstmt = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
            pstmt.setLong(1, message.getSize()); // size
            pstmt.setTimestamp(2, new Timestamp(message.getInternalDate().getTime())); // internaldate
            pstmt.setString(3, header.getSubject()); // subject
            Date sent = header.getDate();
            pstmt.setTimestamp(4, (sent != null) ? new Timestamp(sent.getTime()) : null); // sentdate
            pstmt.setString(5, (header.getFrom() != null) ? header.getFrom().getDisplayString() : null); // fromaddr
            return pstmt;
        }//ww w.j  a va2  s.  c  o m
    }, keyHolder);
    long physmessageid = keyHolder.getKey().longValue();
    message.setPhysMessageID(physmessageid);
    addHeader(physmessageid, header);
    return physmessageid;
}

From source file:com.l2jfree.gameserver.instancemanager.RecommendationManager.java

/**
 * <B>Create an entry in `character_recommend_data`</B>.<BR>
 * Called just after character creation, but may be also called when restoring player's
 * evaluation data and the entry is missing.
 * @param player The newly created player
 *//*from  ww w .  java 2 s.c o m*/
public void onCreate(L2Player player) {
    Connection con = null;
    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);
        PreparedStatement ps = con.prepareStatement(ADD_RECOMMENDATION_INFO);
        ps.setInt(1, player.getObjectId());
        ps.setLong(2, nextUpdate - DAY);
        ps.executeUpdate();
        ps.close();
    } catch (SQLException e) {
        _log.error("Failed creating recommendation data for " + player.getName() + "!", e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

From source file:net.mindengine.oculus.frontend.service.customization.JdbcCustomizationDAO.java

@Override
public long saveUnitCustomizationValue(UnitCustomizationValue unitCustomizationValue) throws Exception {
    UnitCustomizationValue value = null;

    if (unitCustomizationValue.getId() == null || unitCustomizationValue.getId() < 1) {
        value = getUnitCustomizationValue(unitCustomizationValue.getCustomizationId(),
                unitCustomizationValue.getUnitId());
    } else//from  w ww .j  a v a2s  .  c o  m
        value = unitCustomizationValue;

    if (value == null) {
        PreparedStatement ps = getConnection().prepareStatement(
                "insert into unit_customization_values (unit_id, customization_id, value) values (?,?,?)");
        ps.setLong(1, unitCustomizationValue.getUnitId());
        ps.setLong(2, unitCustomizationValue.getCustomizationId());
        ps.setString(3, unitCustomizationValue.getValue());

        logger.info(ps);
        ps.execute();
        ResultSet rs = ps.getGeneratedKeys();
        if (rs.next()) {
            return rs.getLong(1);
        }
    } else {
        update("update unit_customization_values set value = :value where id = :id", "value",
                unitCustomizationValue.getValue(), "id", value.getId());

        return value.getId();
    }
    return 0;
}

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.  j a  v  a2 s . com
        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();
}

From source file:de.iritgo.aktario.jdbc.JDBCManager.java

/**
 * Transfer all attribute values of a data object to the specified
 * prepared statement./*from  ww w .ja v a 2  s .com*/
 *
 * @param object The data object to transfer.
 * @param stmt The prepared statement.
 * @throws SQLException If an attribute could not be set.
 */
private void putAttributesToStatement(DataObject object, PreparedStatement stmt) throws SQLException {
    stmt.setLong(1, object.getUniqueId());

    int pos = 2;

    for (Iterator i = object.getAttributes().entrySet().iterator(); i.hasNext();) {
        Map.Entry attribute = (Map.Entry) i.next();

        if (attribute.getValue() instanceof IObjectList) {
            continue;
        }

        stmt.setObject(pos++, attribute.getValue());
    }
}

From source file:nl.ordina.bag.etl.dao.AbstractBAGMutatiesDAO.java

@Override
public void setMutatiesFileStatus(final long id, final ProcessingStatus status) throws DAOException {
    try {//from  www. jav  a2  s  . com
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection
                        .prepareStatement("update bag_mutaties_file set" + " status = ?" + " where id = ?");
                ps.setInt(1, status.ordinal());
                ps.setLong(2, id);
                return ps;
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException(e);
    }
}

From source file:org.dcache.chimera.H2FsSqlDriver.java

@Override
long createTagInode(int uid, int gid, int mode, byte[] value) {
    final String CREATE_TAG_INODE_WITH_VALUE = "INSERT INTO t_tags_inodes (imode, inlink, iuid, igid, isize, "
            + "ictime, iatime, imtime, ivalue) VALUES (?,1,?,?,?,?,?,?,?)";

    Timestamp now = new Timestamp(System.currentTimeMillis());
    KeyHolder keyHolder = new GeneratedKeyHolder();
    int rc = _jdbc.update(con -> {
        PreparedStatement ps = con.prepareStatement(CREATE_TAG_INODE_WITH_VALUE,
                Statement.RETURN_GENERATED_KEYS);
        ps.setInt(1, mode | UnixPermission.S_IFREG);
        ps.setInt(2, uid);//from   w  ww  .  ja v a2s . c o  m
        ps.setInt(3, gid);
        ps.setLong(4, value.length);
        ps.setTimestamp(5, now);
        ps.setTimestamp(6, now);
        ps.setTimestamp(7, now);
        ps.setBinaryStream(8, new ByteArrayInputStream(value), value.length);
        return ps;
    }, keyHolder);
    if (rc != 1) {
        throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(CREATE_TAG_INODE_WITH_VALUE, 1, rc);
    }
    /* H2 uses weird names for the column with the auto-generated key, so we cannot use the code
     * in the base class.
     */
    return (Long) keyHolder.getKey();
}