List of usage examples for java.sql PreparedStatement setTimestamp
void setTimestamp(int parameterIndex, java.sql.Timestamp x) throws SQLException;
java.sql.Timestamp
value. From source file:com.ccoe.build.dal.SessionJDBCTemplate.java
public int create(final Session session) { final String SQL = "insert into RBT_SESSION (pool_name, machine_name, user_name, environment, " + "status, duration, maven_version, goals, start_time, git_url, git_branch, jekins_url, java_version, cause, full_stacktrace, category, filter) " + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplateObject.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement(SQL, new String[] { "id" }); ps.setString(1, session.getAppName()); ps.setString(2, session.getMachineName()); ps.setString(3, session.getUserName()); ps.setString(4, session.getEnvironment()); ps.setString(5, session.getStatus()); ps.setLong(6, session.getDuration()); ps.setString(7, session.getMavenVersion()); ps.setString(8, session.getGoals()); ps.setTimestamp(9, new java.sql.Timestamp(session.getStartTime().getTime())); ps.setString(10, session.getGitUrl()); ps.setString(11, session.getGitBranch()); ps.setString(12, session.getJenkinsUrl()); ps.setString(13, session.getJavaVersion()); ps.setString(14, getCause(session.getExceptionMessage())); setFullStackTraceAsClob(15, ps, session); ps.setString(16, session.getCategory()); ps.setString(17, session.getFilter()); return ps; }//from ww w . ja v a 2s. c om }, keyHolder); return keyHolder.getKey().intValue(); }
From source file:net.algem.security.UserDaoImpl.java
private void createToken(final int userId, final String token) { String query = "INSERT INTO " + T_TOKEN + " VALUES(?,?,?)"; jdbcTemplate.update(query, new PreparedStatementSetter() { @Override/*from ww w. java 2s . co m*/ public void setValues(PreparedStatement ps) throws SQLException { ps.setInt(1, userId); ps.setString(2, token); ps.setTimestamp(3, new java.sql.Timestamp(new java.util.Date().getTime())); } }); }
From source file:com.skycloud.management.portal.admin.sysmanage.dao.impl.UserManageDaoImpl.java
@Override public int updateUserPwd(final TUserBO user) throws SQLException { int ret = 0;//from w w w . j a v a2s . c om String sql = "update T_SCS_USER set PWD=?, LASTUPDATE_DT=? where ID=?"; try { ret = this.getJdbcTemplate().update(sql, new PreparedStatementSetter() { int i = 1; public void setValues(PreparedStatement ps) throws SQLException { ps.setString(i++, user.getPwd()); ps.setTimestamp(i++, new Timestamp(new Date(System.currentTimeMillis()).getTime())); ps.setInt(i++, user.getId()); } }); } catch (Exception e) { throw new SQLException("? " + user.getLastupdateDt() + " " + e.getMessage()); } return ret; }
From source file:com.skycloud.management.portal.admin.sysmanage.dao.impl.UserManageDaoImpl.java
@Override public int updateUserDynPwd(final TUserBO user) throws SQLException { int ret = 0;// w ww . j a v a2 s .com String sql = "update T_SCS_USER set DYN_PWD=?, LASTUPDATE_DT=? where ID=?"; try { ret = this.getJdbcTemplate().update(sql, new PreparedStatementSetter() { int i = 1; public void setValues(PreparedStatement ps) throws SQLException { ps.setString(i++, user.getDecPwd()); ps.setTimestamp(i++, new Timestamp(new Date(System.currentTimeMillis()).getTime())); ps.setInt(i++, user.getId()); } }); } catch (Exception e) { throw new SQLException("? " + user.getLastupdateDt() + " " + e.getMessage()); } return ret; }
From source file:nl.strohalm.cyclos.utils.hibernate.BasePeriodType.java
public void nullSafeSet(final PreparedStatement st, final Object value, final int index, final SessionImplementor session) throws HibernateException, SQLException { final Period period = (Period) value; Timestamp begin = null;//from ww w . j ava 2 s . c o m Timestamp end = null; if (period != null && period.getBegin() != null) { begin = new Timestamp(period.getBegin().getTimeInMillis()); } if (period != null && period.getEnd() != null) { end = new Timestamp(period.getEnd().getTimeInMillis()); } st.setTimestamp(index + BEGIN, begin); st.setTimestamp(index + END, end); if (getLog().isDebugEnabled()) { getLog().debug("Binding " + begin + " to parameter: " + (index + BEGIN)); getLog().debug("Binding " + end + " to parameter: " + (index + END)); } }
From source file:net.bhira.sample.api.dao.CompanyDaoImpl.java
/** * @see net.bhira.sample.api.dao.CompanyDao#save(net.bhira.sample.model.Company) *//*from w w w .j a v a 2 s. c o m*/ @Override public void save(Company company) throws ObjectNotFoundException, InvalidObjectException, InvalidReferenceException { if (company == null) { throw new InvalidObjectException("Company object is null."); } company.initForSave(); company.validate(); boolean isNew = company.isNew(); int count = 0; if (isNew) { // for new company, construct SQL insert statement KeyHolder keyHolder = new GeneratedKeyHolder(); count = jdbcTemplate.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement pstmt = connection.prepareStatement(SQL_INSERT, Statement.RETURN_GENERATED_KEYS); pstmt.setString(1, company.getName()); pstmt.setString(2, company.getIndustry()); pstmt.setString(3, company.getBillingAddress()); pstmt.setString(4, company.getShippingAddress()); pstmt.setTimestamp(5, new Timestamp(company.getCreated().getTime())); pstmt.setTimestamp(6, new Timestamp(company.getModified().getTime())); pstmt.setString(7, company.getCreatedBy()); pstmt.setString(8, company.getModifiedBy()); return pstmt; } }, keyHolder); // fetch the newly created auto-increment ID company.setId(keyHolder.getKey().longValue()); LOG.debug("inserted company, count = {}, id = {}", count, company.getId()); } else { // for existing company, construct SQL update statement Object[] args = new Object[] { company.getName(), company.getIndustry(), company.getBillingAddress(), company.getShippingAddress(), company.getModified(), company.getModifiedBy(), company.getId() }; count = jdbcTemplate.update(SQL_UPDATE, args); LOG.debug("updated company, count = {}, id = {}", count, company.getId()); } // if insert/update has 0 count value, then throw exception if (count <= 0) { throw new ObjectNotFoundException("Company with ID " + company.getId() + " was not found."); } // update dependent entries, as needed if (isNew) { // for new model if there is contact info, save it to contact info table and then // add entry in relationship table if (company.getContactInfo() != null) { contactInfoDao.save(company.getContactInfo()); Object[] args = new Object[] { company.getId(), company.getContactInfo().getId() }; jdbcTemplate.update(SQL_CINFO_REL_INSERT, args); } } else { // for existing model, fetch contact info ID from relationship table List<Long> cinfoIds = jdbcTemplate.queryForList(SQL_CINFO_REL_LOAD, Long.class, new Object[] { company.getId() }); Long cinfoId = (cinfoIds != null && !cinfoIds.isEmpty()) ? cinfoIds.get(0) : null; if (company.getContactInfo() == null) { // clean up old contact info entry, if needed if (cinfoId != null) { jdbcTemplate.update(SQL_CINFO_REL_DELETE, new Object[] { company.getId() }); contactInfoDao.delete(cinfoId); } } else { // insert/update contact info entry if (cinfoId != null) { company.getContactInfo().setId(cinfoId); contactInfoDao.save(company.getContactInfo()); } else { contactInfoDao.save(company.getContactInfo()); Object[] args = new Object[] { company.getId(), company.getContactInfo().getId() }; jdbcTemplate.update(SQL_CINFO_REL_INSERT, args); } } } }
From source file:net.sf.infrared.collector.impl.persistence.ApplicationStatisticsDaoImpl.java
private void insertTree(final String appName, final String hostName, final Tree tree) { byte[] byteArray = null; try {//from w ww.j av a 2 s. c om ByteArrayOutputStream baos = serializeObject(tree); byteArray = baos.toByteArray(); } catch (IOException e) { log.error("IOException : Unable to serialize the Aggregate Operation Tree Object"); } final ByteArrayInputStream bais = new ByteArrayInputStream(byteArray); getJdbcTemplate().update(SQL_INSERT_TREE, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, appName); ps.setString(2, hostName); ps.setBinaryStream(3, bais, bais.available()); ps.setTimestamp(4, new Timestamp(System.currentTimeMillis())); } }); }
From source file:com.agiletec.plugins.jpcrowdsourcing.aps.system.services.ideainstance.IdeaInstanceDAO.java
private void updateIdeaInstance(IdeaInstance ideainstance, Connection conn) { PreparedStatement stat = null; try {/*from ww w. j a v a 2s . com*/ stat = conn.prepareStatement(UPDATE_IDEAINSTANCE); int index = 1; if (null != ideainstance.getCreatedat()) { Timestamp createdatTimestamp = new Timestamp(ideainstance.getCreatedat().getTime()); stat.setTimestamp(index++, createdatTimestamp); } else { stat.setNull(index++, Types.DATE); } stat.setString(index++, ideainstance.getCode()); stat.executeUpdate(); } catch (Throwable t) { _logger.error("Error updating ideainstance ", t); throw new RuntimeException("Error updating ideainstance ", t); } finally { this.closeDaoResources(null, stat, null); } }
From source file:com.surevine.alfresco.audit.repo.JdbcAuditRepository.java
/** * Simple write to the database of the audit object. * /*from w ww. j a v a2 s .com*/ * @see com.surevine.alfresco.audit.AuditRepository#audit(com.surevine.alfresco.audit.Auditable) */ public void audit(final Auditable toAudit) { this.jdbcTemplate.update(UPDATE_SQL, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, truncate(toAudit.getUser(), 40)); ps.setString(2, truncate(toAudit.getAction(), 40)); ps.setString(3, truncate(toAudit.getSource(), 80)); ps.setString(4, truncate(toAudit.getSecLabel(), 1024)); ps.setString(5, truncate(toAudit.getSite(), 80)); ps.setString(6, truncate(toAudit.getDetails(), 256)); ps.setString(7, truncate(toAudit.getUrl(), 256)); ps.setString(8, truncate(toAudit.getVersion(), 10)); ps.setTimestamp(9, new java.sql.Timestamp(System.currentTimeMillis())); ps.setString(10, truncate(toAudit.getRemoteAddress(), 40)); ps.setString(11, Boolean.toString(toAudit.isSuccess())); ps.setString(12, truncate(toAudit.getTags(), 256)); ps.setString(13, truncate(toAudit.getNodeRef(), 80)); ps.setLong(14, toAudit.getTimeSpent()); } }); }
From source file:com.alfaariss.oa.util.saml2.storage.artifact.jdbc.JDBCArtifactMapFactory.java
/** * Remove all expired artifacts./*from ww w . ja va2 s .co m*/ * * e.g. <code>DELETE FROM artifacts WHERE expiration <= NOW()</code> * @see ICleanable#removeExpired() */ public void removeExpired() throws PersistenceException { Connection oConnection = null; PreparedStatement ps = null; try { oConnection = _oDataSource.getConnection(); ps = oConnection.prepareStatement(_sRemoveExpiredQuery); ps.setTimestamp(1, new Timestamp(System.currentTimeMillis())); int i = ps.executeUpdate(); if (i > 0) _logger.debug(i + " artifact(s) expired"); } catch (SQLException e) { _logger.error("Could not execute delete expired", e); throw new PersistenceException(SystemErrors.ERROR_RESOURCE_REMOVE, e); } catch (Exception e) { _logger.error("Internal error while delete expired artifacts", e); throw new PersistenceException(SystemErrors.ERROR_RESOURCE_REMOVE, e); } finally { try { if (ps != null) ps.close(); } catch (SQLException e) { _logger.debug("Could not close statement", e); } try { if (oConnection != null) oConnection.close(); } catch (SQLException e) { _logger.debug("Could not close connection", e); } } }