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:dk.netarkivet.common.utils.DBUtils.java

/**
 * Insert a long value (which could be null) into
 * the given field of a statement.//from www . j a va2 s  . c  o  m
 * @param s a prepared Statement
 * @param i the number of a given field in the prepared statement
 * @param value the long value to insert (maybe null)
 * @throws SQLException If i does not correspond to a
 * parameter marker in the PreparedStatement, or a database access error
 * occurs or this method is called on a closed PreparedStatement
 */
public static void setLongMaybeNull(PreparedStatement s, int i, Long value) throws SQLException {
    ArgumentNotValid.checkNotNull(s, "PreparedStatement s");
    if (value != null) {
        s.setLong(i, value);
    } else {
        s.setNull(i, Types.BIGINT);
    }
}

From source file:sample.contact.dao.impl.MenuDaoImpl.java

public void delete(final Long menuId) {
    getJdbcTemplate().update("delete from menus where id = ?", new PreparedStatementSetter() {
        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setLong(1, menuId);
        }//from   w  ww.ja v a  2  s  .com
    });
}

From source file:me.redstarstar.rdfx.duty.dao.jdbc.ScheduleJdbcDao.java

@Override
public void delete(long parentId, int week) {
    jdbcTemplate.execute("DELETE FROM schedule WHERE parent_id = ? AND week = ?",
            (PreparedStatement preparedStatement) -> {
                preparedStatement.setLong(1, parentId);
                preparedStatement.setInt(2, week);
                preparedStatement.execute();
                return null;
            });//from  www  .  ja v  a2s  .c om
}

From source file:me.redstarstar.rdfx.duty.dao.jdbc.ScheduleJdbcDao.java

@Override
public void save(Schedule schedule) {
    jdbcTemplate.execute("INSERT INTO schedule (parent_id, week, activity_date, create_date, update_date) "
            + "VALUES (?, ?, ?, NOW(), NOW());", (PreparedStatement preparedStatement) -> {
                preparedStatement.setLong(1, schedule.getParentId());
                preparedStatement.setInt(2, schedule.getWeek());
                preparedStatement.setDate(3, Date.valueOf(schedule.getActivityDate()));
                preparedStatement.execute();
                return null;
            });/* w  w w  .  j a  v a 2s  .  c om*/
}

From source file:at.alladin.rmbt.db.dao.TestStatDao.java

@Override
public int save(TestStat result) throws SQLException {
    final String sql = "INSERT INTO test_stat (test_uid, cpu_usage, mem_usage) VALUES (?,?::json,?::json)";
    final PreparedStatement ps = conn.prepareStatement(sql);
    ps.setLong(1, result.getTestUid());
    ps.setString(2, result.getCpuUsage().toString());
    ps.setString(3, result.getMemUsage().toString());
    return ps.executeUpdate();
}

From source file:com.recomdata.grails.rositaui.etl.dao.ValidationErrorBatchPreparedStatementSetter.java

@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
    ValidationError v = items.get(i);//from   w w  w  .  j  a va  2s.co m
    ps.setString(1, v.getType());
    ps.setLong(2, v.getLineNumber());
    ps.setString(3, v.getMessage());
    ps.setTimestamp(4, new Timestamp(v.getDate().getTime()));
    ps.setString(5, v.getSchema());
    ps.setString(6, v.getLocation());
    ps.setString(7, v.getSourceType());
    ps.setString(8, v.getFilename());
}

From source file:dao.CarryonRecentAddQuery.java

/**
 * This method is not called by spring.//from  www.  ja va  2s  .c om
 * This method adds an entry into pblob
 * @param conn the connection
 * @param ownerid 
 * @param entryid 
 * @param category 
 * @param btitle 
 * @param mimeType 
 * @param bsize 
 * @param zoom 
 * @param caption 
 * @exception BaseDaoException
 */
public void run(Connection conn, String ownerid, String entryid, int category, String btitle, String mimeType,
        long bsize, int zoom, String caption) throws BaseDaoException {

    byte[] capBytes = { ' ' };
    if (!RegexStrUtil.isNull(caption)) {
        capBytes = caption.getBytes();
    }
    String stmt = "insert into pblob values(?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP(), ?, ?, ?, ?)";
    PreparedStatement s = null;
    try {
        s = conn.prepareStatement(stmt);
        s.setLong(1, 0);
        s.setLong(2, new Long(entryid));
        s.setLong(3, new Long(ownerid));
        s.setInt(4, new Integer(category));
        s.setString(5, mimeType);
        s.setString(6, btitle);
        s.setLong(7, bsize);
        s.setInt(8, new Integer(zoom));
        s.setInt(9, 0);
        s.setBytes(10, capBytes);
        s.executeUpdate();
    } catch (SQLException e) {
        logger.error("Error adding a blob.", e);
        throw new BaseDaoException("Error adding pblob " + stmt, e);
    }
}

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

public boolean saveAccident(Accident acc) {
    try {//from  www .j a v a2  s.com
        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:com.micromux.cassandra.jdbc.SpashScreenTest.java

@Test
public void test() throws Exception {
    String query = "UPDATE Test SET a=?, b=? WHERE KEY=?";
    PreparedStatement statement = con.prepareStatement(query);
    try {/*from  www.jav  a 2 s  . c o m*/
        statement.setLong(1, 100);
        statement.setLong(2, 1000);
        statement.setString(3, "key0");

        statement.executeUpdate();
    } finally {
        statement.close();
    }
}

From source file:org.gridobservatory.greencomputing.dao.TimeseriesDao.java

protected void insertTimeSeriesAcquisitions(final BigInteger timeSeriesId,
        final List<TimeseriesAcquisitionType> acquisitions) {
    executor.submit(new Runnable() {
        @Override//w  w w  .  ja  va 2 s.c  om
        public void run() {
            if (acquisitions != null) {
                getJdbcTemplate().batchUpdate(
                        "insert into time_series_acquisition (time_series_id, ts, value) values (?,?,?)",
                        new BatchPreparedStatementSetter() {

                            @Override
                            public void setValues(PreparedStatement ps, int i) throws SQLException {
                                ps.setLong(1, timeSeriesId.longValue());
                                long dateInMilis = acquisitions.get(i).getTs()
                                        .multiply(BigInteger.valueOf(1000l)).longValue();
                                ps.setTimestamp(2, new Timestamp(dateInMilis));
                                ps.setBigDecimal(3, new BigDecimal(acquisitions.get(i).getV()));
                            }

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