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:com.jagornet.dhcp.db.JdbcIaPrefixDAO.java

public List<IaPrefix> findAllByIdentityAssocId(final long identityAssocId) {
    return getJdbcTemplate().query("select * from iaprefix where identityassoc_id = ? order by prefixaddress",
            new PreparedStatementSetter() {
                @Override//  w ww  .java2 s  .  c  o  m
                public void setValues(PreparedStatement ps) throws SQLException {
                    ps.setLong(1, identityAssocId);
                }
            }, new IaPrefixRowMapper());
}

From source file:com.l2jfree.gameserver.model.entity.GrandBossState.java

public void save() {
    Connection con = null;// w ww  . j ava 2  s  .  c o  m

    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);
        PreparedStatement statement = con.prepareStatement(
                "INSERT INTO grandboss_intervallist (bossId,respawnDate,state) VALUES(?,?,?)");
        statement.setInt(1, _bossId);
        statement.setLong(2, _respawnDate);
        statement.setInt(3, _state.ordinal());
        statement.execute();
        statement.close();
    } catch (Exception e) {
        _log.error(e.getMessage(), e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

From source file:com.starit.diamond.server.service.DBPersistService.java

public void addConfigInfo(final Timestamp time, final ConfigInfo configInfo) {
    final Long id = this.jt.queryForObject("SELECT MAX(ID) FROM config_info", Long.class);

    this.jt.update(
            "insert into config_info (id, data_id,group_id, username, content,md5,gmt_create,gmt_modified, description) values(?,?,?,?,?,?,?,?,?)",
            new PreparedStatementSetter() {
                public void setValues(PreparedStatement ps) throws SQLException {

                    int index = 1;
                    if (id == null)
                        ps.setLong(index++, 1);
                    else
                        ps.setLong(index++, (Long) id + 1);

                    ps.setString(index++, configInfo.getDataId());
                    ps.setString(index++, configInfo.getGroup());
                    ps.setString(index++, configInfo.getUserName());
                    ps.setString(index++, configInfo.getContent());
                    ps.setString(index++, configInfo.getMd5());
                    ps.setTimestamp(index++, time);
                    ps.setTimestamp(index++, time);
                    ps.setString(index++, configInfo.getDescription());
                }//  w w  w  . ja v  a2s .c o  m

            });
}

From source file:eionet.cr.dao.virtuoso.VirtuosoSpoBinaryDAO.java

public SpoBinaryDTO get(String subjectUri) throws DAOException {

    if (StringUtils.isBlank(subjectUri)) {
        throw new IllegalArgumentException("Subject uri must not be blank");
    }//from   w w w  . j  av a2s .c  om

    ResultSet rs = null;
    PreparedStatement stmt = null;
    Connection conn = null;
    try {
        conn = getSQLConnection();
        stmt = conn.prepareStatement(SQL_GET);
        stmt.setLong(1, Hashes.spoHash(subjectUri));
        rs = stmt.executeQuery();
        if (rs != null && rs.next()) {

            SpoBinaryDTO dto = new SpoBinaryDTO(rs.getLong("SUBJECT"));
            dto.setContentType(rs.getString("DATATYPE"));
            dto.setLanguage(rs.getString("OBJ_LANG"));
            dto.setMustEmbed(YesNoBoolean.parse(rs.getString("MUST_EMBED")));

            return dto;
        }
    } catch (SQLException e) {
        throw new DAOException(e.getMessage(), e);
    } finally {
        SQLUtil.close(rs);
        SQLUtil.close(stmt);
        SQLUtil.close(conn);
    }

    return null;
}

From source file:dk.netarkivet.harvester.datamodel.extendedfield.ExtendedFieldTypeDBDAO.java

/**
 * Read an ExtendedFieldType from database belonging to the given id.
 * @param connection an open connection to the database
 * @param aExtendedfieldtypeId an id belonging to a ExtendedFieldType
 * @return an ExtendedFieldType from database belonging to the given id.
 *///from ww w  .j  ava2  s  .c o  m
private synchronized ExtendedFieldType read(Connection connection, Long aExtendedfieldtypeId) {
    if (!exists(connection, aExtendedfieldtypeId)) {
        throw new UnknownID(
                "Extended FieldType id " + aExtendedfieldtypeId + " is not known in persistent storage");
    }

    ExtendedFieldType extendedFieldType = null;
    PreparedStatement statement = null;
    try {
        statement = connection.prepareStatement(
                "" + "SELECT name " + "FROM   extendedfieldtype " + "WHERE  extendedfieldtype_id = ? ");

        statement.setLong(1, aExtendedfieldtypeId);
        ResultSet result = statement.executeQuery();
        result.next();

        String name = result.getString(1);

        extendedFieldType = new ExtendedFieldType(aExtendedfieldtypeId, name);

        return extendedFieldType;
    } catch (SQLException e) {
        String message = "SQL error reading extended Field " + aExtendedfieldtypeId + " in database" + "\n"
                + ExceptionUtils.getSQLExceptionCause(e);
        log.warn(message, e);
        throw new IOFailure(message, e);
    }
}

From source file:gobblin.data.management.retention.sql.SqlBasedRetentionPoc.java

/**
 * The test inserts a few time partitioned datasets. A query is issued that retrieves the partitions older than 2
 * years./* w  w  w  .  jav a  2s  .c om*/
 */
@Test
public void testKeepLast2YearsOfDailyPartitions() throws Exception {

    insertDailyPartition(new Path("/data/tracking/MetricEvent/daily/2015/11/25")); //61 days
    insertDailyPartition(new Path("/data/tracking/MetricEvent/daily/2015/12/01")); // 55 days
    insertDailyPartition(new Path("/data/tracking/MetricEvent/daily/2014/11/21")); // 430 days
    insertDailyPartition(new Path("/data/tracking/MetricEvent/daily/2014/01/22")); // 733 days (more than 2 years)
    insertDailyPartition(new Path("/data/tracking/MetricEvent/daily/2013/01/25")); // 1095 days (more than 2 years)

    // Use the current timestamp for consistent test results.
    Timestamp currentTimestamp = new Timestamp(
            DateTimeFormat.forPattern(DAILY_PARTITION_PATTERN).parseDateTime("2016/01/25").getMillis());

    PreparedStatement statement = connection
            .prepareStatement("SELECT path FROM Daily_Partitions WHERE TIMESTAMP_DIFF(?, ts, 'Days') > ?");
    statement.setTimestamp(1, currentTimestamp);
    statement.setLong(2, TWO_YEARS_IN_DAYS);
    ResultSet rs = statement.executeQuery();

    // Daily partitions to be cleaned
    rs.next();
    Assert.assertEquals(rs.getString(1), "/data/tracking/MetricEvent/daily/2014/01/22");
    rs.next();
    Assert.assertEquals(rs.getString(1), "/data/tracking/MetricEvent/daily/2013/01/25");

}

From source file:iddb.runtime.db.model.dao.impl.mysql.UserDAOImpl.java

@Override
public User get(Long key) throws EntityDoesNotExistsException {
    String sql = "select * from user where id = ? limit 1";
    Connection conn = null;//from   w w  w.j a v a2s  .  c  o  m
    User user = null;
    try {
        conn = ConnectionFactory.getMasterConnection();
        PreparedStatement st = conn.prepareStatement(sql);
        st.setLong(1, key);
        ResultSet rs = st.executeQuery();
        if (rs.next()) {
            user = new User();
            loadUser(user, rs);
        } else {
            throw new EntityDoesNotExistsException("User with id %s was not found", key);
        }
    } catch (SQLException e) {
        logger.error("get: {}", e);
    } catch (IOException e) {
        logger.error("get: {}", e);
    } finally {
        try {
            if (conn != null)
                conn.close();
        } catch (Exception e) {
        }
    }
    return user;
}

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

public void setPreparedStatementValue(int iindex, String value, PreparedStatement pstmt, AbsDatabaseType dbtype)
        throws SQLException {
    log.debug("setLong(" + iindex + "," + value + ")");
    Object objTmp = label2value(value);
    if (objTmp == null) {
        pstmt.setObject(iindex, null, java.sql.Types.BIGINT);
    } else {/*from   w  w w  . j av  a 2 s .  c o m*/
        pstmt.setLong(iindex, (Long) objTmp);
    }
}

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

/**
 * //ww w  .ja  v a  2  s . c  o  m
 * @param result
 * @param columnNames
 * @throws SQLException
 */
public int updateCounter(QoSTestResult result, PreparedStatement ps) throws SQLException {
    ps.setInt(1, result.getSuccessCounter());
    ps.setInt(2, result.getFailureCounter());
    ps.setLong(3, result.getUid());
    return ps.executeUpdate();
}

From source file:net.solarnetwork.node.dao.jdbc.general.JdbcGeneralLocationDatumDao.java

@Override
protected void setStoreStatementValues(GeneralLocationDatum datum, PreparedStatement ps) throws SQLException {
    int col = 0;/*from  w w  w.  j  a v  a  2 s.co m*/
    ps.setTimestamp(++col, new java.sql.Timestamp(
            datum.getCreated() == null ? System.currentTimeMillis() : datum.getCreated().getTime()));
    ps.setLong(++col, datum.getLocationId());
    ps.setString(++col, datum.getSourceId() == null ? "" : datum.getSourceId());

    String json;
    try {
        json = objectMapper.writeValueAsString(datum.getSamples());
    } catch (IOException e) {
        log.error("Error serializing GeneralDatumSamples into JSON: {}", e.getMessage());
        json = "{}";
    }
    ps.setString(++col, json);
}