List of usage examples for java.sql PreparedStatement setLong
void setLong(int parameterIndex, long x) throws SQLException;
long
value. From source file:com.jagornet.dhcp.db.JdbcIdentityAssocDAO.java
public void update(final IdentityAssoc ia) { String updateQuery = "update identityassoc" + " set duid=?," + " iatype=?," + " iaid=?," + " state=?" + " where id=?"; getJdbcTemplate().update(updateQuery, new PreparedStatementSetter() { @Override//from www. ja va2s . c o m public void setValues(PreparedStatement ps) throws SQLException { ps.setBytes(1, ia.getDuid()); ps.setByte(2, ia.getIatype()); ps.setLong(3, ia.getIaid()); ps.setByte(4, ia.getState()); ps.setLong(5, ia.getId()); } }); }
From source file:henu.dao.impl.CaclDaoImpl.java
@Override public boolean createCacl(Cacl cacl) { String sql = "insert into cacl (cid, cname, structure, author, postime) values(?, ?,?,?,?)"; PreparedStatement ps = SqlDB.executePreparedStatement(sql); int result = 0; try {// w ww.ja va 2 s .com ps.setLong(1, cacl.getTid()); ps.setString(2, cacl.getName()); ps.setString(3, cacl.getStructure()); ps.setLong(4, cacl.getAuthor()); ps.setTimestamp(5, new Timestamp(System.currentTimeMillis())); result = ps.executeUpdate(); } catch (SQLException ex) { } return result > 0 && recordCaclUser(cacl.getTid(), cacl.getUsers()); }
From source file:com.gvmax.data.queue.JDBCBasedQueueDAO.java
@Override @Timed/*from w ww . j a v a 2 s .c om*/ @ExceptionMetered public long enqueue(T obj) throws IOException { final String payload = toJson(obj); KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection conn) throws SQLException { PreparedStatement ps = conn.prepareStatement( "insert into " + tableName + " ( enqueuedDate, payload ) values (?,?)", new String[] { "id" }); ps.setLong(1, System.currentTimeMillis()); ps.setString(2, payload); return ps; } }, keyHolder); return keyHolder.getKey().longValue(); }
From source file:alfio.manager.FileUploadManager.java
public String insertFile(UploadBase64FileModification file) { String digest = DigestUtils.sha256Hex(file.getFile()); if (Integer.valueOf(1).equals(repository.isPresent(digest))) { return digest; }/*from w ww .j a va 2 s . com*/ LobHandler lobHandler = new DefaultLobHandler(); jdbc.getJdbcOperations().execute(repository.uploadTemplate(), new AbstractLobCreatingPreparedStatementCallback(lobHandler) { @Override protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException { ps.setString(1, digest); ps.setString(2, file.getName()); ps.setLong(3, file.getFile().length); lobCreator.setBlobAsBytes(ps, 4, file.getFile()); ps.setString(5, file.getType()); ps.setString(6, Json.GSON.toJson(getAttributes(file))); } }); return digest; }
From source file:com.sinet.gage.dao.DomainsRepository.java
/** * /*from w w w . ja v a2 s .c om*/ * @param domains */ public void insertDomains(List<Domain> domains) { try { jdbcTemplate.batchUpdate(DOMAINS_INSERT_SQL, new BatchPreparedStatementSetter() { public int getBatchSize() { if (domains == null) return 0; return domains.size(); } @Override public void setValues(PreparedStatement ps, int i) throws SQLException { Domain domain = domains.get(i); ps.setLong(1, domain.getDomainId()); ps.setObject(2, domain.getGuid()); ps.setString(3, domain.getDomainName()); ps.setString(4, domain.getLoginPrefix()); ps.setLong(5, domain.getFlag()); ps.setString(6, domain.getDomainType()); ps.setLong(7, domain.getParentDomainId()); ps.setString(8, domain.getParentDomainName()); ps.setLong(9, domain.getStateDomainId()); ps.setString(10, domain.getStateDomainName()); ps.setString(11, domain.getLicenseType()); ps.setString(12, domain.getLicensePoolType()); ps.setInt(13, domain.getNoOfLicense()); ps.setBoolean(14, domain.isPilot()); ps.setDate(15, domain.getPilotStartDate()); ps.setDate(16, domain.getPilotEndDate()); ps.setBoolean(17, domain.isFullSubscription()); ps.setObject(18, domain.getSubscriptionStartDate()); ps.setObject(19, domain.getSubscriptionEndDate()); ps.setLong(20, domain.getCreatorUserId()); ps.setTimestamp(21, domain.getCreationDate()); ps.setLong(22, domain.getModifierUserId()); ps.setTimestamp(23, domain.getModifiedDate()); } }); } catch (Exception e) { log.error("Error in inserting Domains", e); } }
From source file:nl.ordina.bag.etl.dao.AbstractBAGMutatiesDAO.java
@Override public void delete(final BAGMutatie mutatie) { try {/*from www. j a v a2 s .c om*/ jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement("delete from bag_mutatie" + " where id = ?"); ps.setLong(1, mutatie.getId()); return ps; } }); } catch (DataAccessException e) { throw new DAOException(e); } }
From source file:com.l2jfree.gameserver.model.entity.GrandBossState.java
public void update() { Connection con = null;//w ww .j a v a2 s .c o m try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement( "UPDATE grandboss_intervallist SET respawnDate = ?,state = ? WHERE bossId = ?"); statement.setLong(1, _respawnDate); statement.setInt(2, _state.ordinal()); statement.setInt(3, _bossId); statement.execute(); statement.close(); _log.info("update GrandBossState : ID-" + _bossId + ",RespawnDate-" + _respawnDate + ",State-" + _state.toString()); } catch (Exception e) { _log.warn("Exeption on update GrandBossState : ID-" + _bossId + ",RespawnDate-" + _respawnDate + ",State-" + _state.toString(), e); } finally { L2DatabaseFactory.close(con); } }
From source file:de.iritgo.aktario.jdbc.StoreUser.java
/** * Perform the command.//from w ww . j av a2s. c o m */ public void perform() { if (properties.get("id") == null) { Log.logError("persist", "StoreUser", "Missing unique id for the user to store"); return; } UserRegistry userRegistry = Server.instance().getUserRegistry(); long userId = ((Long) properties.get("id")).longValue(); User user = userRegistry.getUser(userId); if (user == null) { Log.logError("persist", "StoreUser", "Unable to find user with id " + userId); return; } 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("delete from IritgoUser where id=?"); stmt.setLong(1, userId); stmt.execute(); stmt.close(); String userSql = "insert into IritgoUser (id, name, password, email) " + " values (?, ?, ?, ?)"; stmt = connection.prepareStatement(userSql); stmt.setLong(1, userId); stmt.setString(2, user.getName()); stmt.setString(3, user.getPassword()); stmt.setString(4, user.getEmail()); stmt.execute(); stmt.close(); stmt = connection.prepareStatement("delete from IritgoNamedObjects where userId=?"); stmt.setLong(1, userId); stmt.execute(); stmt.close(); Log.logVerbose("persist", "StoreUser", "INSERT USER " + userId + " |" + userSql + "|"); } catch (SQLException x) { Log.logError("persist", "StoreUser", "Error while storing user with id " + userId + ": " + x); } finally { DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(connection); } }
From source file:com.onclave.testbench.jdbcTemplate.DAOSupport.StudentDAOImplementation.java
@Override public boolean changeActivityStatusOfStudent(final long idStudent, final boolean activityStatus) { final int result = jdbcTemplate.update(new PreparedStatementCreator() { @Override/*from w w w . j a v a 2s . co m*/ public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement preparedStatement = connection .prepareStatement(QueryStatements.UPDATE_STUDENT_ACTIVITY_SQL); preparedStatement.setBoolean(1, activityStatus); preparedStatement.setLong(2, idStudent); return preparedStatement; } }); if (result > 0) { return true; } return false; }
From source file:com.aurel.track.dbase.MigrateTo37.java
private static void addStatusChange(PreparedStatement pstmtStatusChangeFirst, PreparedStatement pstmtStatusChange, Integer fieldChangeID, Integer transactionID, Integer newStatus, Integer oldStatus) {// w w w . j a v a 2 s . c o m if (oldStatus == null) { try { pstmtStatusChangeFirst.setInt(1, fieldChangeID); pstmtStatusChangeFirst.setInt(2, SystemFields.STATE); pstmtStatusChangeFirst.setInt(3, transactionID); pstmtStatusChangeFirst.setInt(4, newStatus); pstmtStatusChangeFirst.setLong(5, SystemFields.STATE); pstmtStatusChangeFirst.setInt(6, ValueType.SYSTEMOPTION); pstmtStatusChangeFirst.setString(7, UUID.randomUUID().toString()); pstmtStatusChangeFirst.executeUpdate(); } catch (Exception e) { LOGGER.error( "Adding a field change for status with transactionID " + transactionID + " fieldChangeID " + fieldChangeID + " new status " + newStatus + " failed with " + e.getMessage(), e); System.err.println(ExceptionUtils.getStackTrace(e)); } } else { try { pstmtStatusChange.setInt(1, fieldChangeID); pstmtStatusChange.setInt(2, SystemFields.STATE); pstmtStatusChange.setInt(3, transactionID); pstmtStatusChange.setInt(4, newStatus); pstmtStatusChange.setInt(5, oldStatus); pstmtStatusChange.setLong(6, SystemFields.STATE); pstmtStatusChange.setInt(7, ValueType.SYSTEMOPTION); pstmtStatusChange.setString(8, UUID.randomUUID().toString()); pstmtStatusChange.executeUpdate(); } catch (Exception e) { LOGGER.error("Adding a field change for status with transactionID " + transactionID + " fieldChangeID " + fieldChangeID + " new status " + newStatus + " oldStatus " + oldStatus + " failed with " + e.getMessage(), e); System.err.println(ExceptionUtils.getStackTrace(e)); } } }