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:org.spring.data.gemfire.app.dao.provider.JdbcUserDao.java
protected PreparedStatement setTimestamp(final PreparedStatement statement, final int parameterIndex, final Timestamp value) throws SQLException { if (value != null) { statement.setTimestamp(parameterIndex, value); } else {/*from w w w . j av a 2 s . c o m*/ statement.setNull(parameterIndex, Types.TIMESTAMP); } return statement; }
From source file:net.duckling.ddl.service.resource.dao.StarmarkDAOImpl.java
@Override public int batchCreate(final String uid, final int tid, final List<Long> rids) { this.getJdbcTemplate().batchUpdate(SQL_CREATE, new BatchPreparedStatementSetter() { @Override//from w ww . j a va 2 s.co m public int getBatchSize() { return (null == rids || rids.isEmpty()) ? 0 : rids.size(); } @Override public void setValues(PreparedStatement ps, int index) throws SQLException { int i = 0; long rid = rids.get(index); ps.setInt(++i, (int) rid); ps.setInt(++i, tid); ps.setString(++i, uid); ps.setTimestamp(++i, new Timestamp((new Date()).getTime())); } }); return 1; }
From source file:com.mvdb.etl.dao.impl.JdbcOrderDAO.java
@Override public void insertBatch(final List<Order> orders) { String sql = "INSERT INTO ORDERS " + "(ORDER_ID, NOTE, SALE_CODE, CREATE_TIME, UPDATE_TIME) VALUES (?, ?, ?, ?, ?)"; getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() { @Override/*from w ww. ja v a 2s. c o m*/ public void setValues(PreparedStatement ps, int i) throws SQLException { Order order = orders.get(i); ps.setLong(1, order.getOrderId()); ps.setString(2, order.getNote()); ps.setInt(3, order.getSaleCode()); ps.setTimestamp(4, new java.sql.Timestamp(order.getCreateTime().getTime())); ps.setTimestamp(5, new java.sql.Timestamp(order.getUpdateTime().getTime())); } @Override public int getBatchSize() { return orders.size(); } }); }
From source file:com.surveypanel.dao.JDBCFormDAO.java
@Override public boolean qualify(String formId, long surveyId, Map<String, Object> defaultValues) { FormDTO load = load(formId, surveyId); Map<String, Object> values = defaultValues; values.putAll(load.getValues());//from w ww .j a v a2s . c om String sql = "INSERT INTO survey_values_" + surveyId + " (question,name,value,formId,surveyId,created) VALUES (?,?,?,?,?,?);"; final Object[][] args = new Object[values.size()][5]; int count = 0; for (Entry<String, Object> value : values.entrySet()) { String fieldName = value.getKey(); String[] key = fieldName.split("_"); args[count] = new Object[] { key[0], fieldName, (String) value.getValue(), formId, surveyId }; count++; } final int counter = values.size(); batchUpdate(sql, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setString(1, (String) args[i][0]); ps.setString(2, (String) args[i][1]); ps.setString(3, (String) args[i][2]); ps.setString(4, (String) args[i][3]); ps.setLong(5, (Long) args[i][4]); ps.setTimestamp(6, new Timestamp(Calendar.getInstance().getTimeInMillis())); } public int getBatchSize() { return counter; } }); update("UPDATE survey_" + surveyId + " SET qualified = true WHERE id = ?", new Object[] { formId }); return false; }
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 {//from w ww. ja v a 2 s . c o m 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.adanac.module.blog.dao.RecordDao.java
public Integer save(String username, String title, String record, String content) { return execute(new TransactionalOperation<Integer>() { @Override/*w ww. ja v a 2s . c om*/ public Integer doInConnection(Connection connection) { String sql = "insert into records (username,title,record,content,create_date) values (?,?,?,?,?)"; try { PreparedStatement statement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); statement.setString(1, username); statement.setString(2, title); statement.setString(3, record); statement.setString(4, content); statement.setTimestamp(5, new Timestamp(System.currentTimeMillis())); int result = statement.executeUpdate(); if (result > 0) { ResultSet keyResultSet = statement.getGeneratedKeys(); if (keyResultSet.next()) { return keyResultSet.getInt(1); } } } catch (SQLException e) { throw new RuntimeException(e); } return null; } }); }
From source file:com.act.lcms.db.model.CuratedStandardMetlinIon.java
protected void bindInsertOrUpdateParameters(PreparedStatement stmt, String note, LocalDateTime createdAtDate, String bestMetlinIon, Integer standardIonResultId, String author) throws SQLException, IOException { stmt.setString(DB_FIELD.NOTE.getInsertUpdateOffset(), note); stmt.setTimestamp(DB_FIELD.CREATED_AT.getInsertUpdateOffset(), new Timestamp(createdAtDate.toDateTime(utcDateTimeZone).getMillis())); stmt.setString(DB_FIELD.BEST_METLIN_ION.getInsertUpdateOffset(), bestMetlinIon); stmt.setString(DB_FIELD.AUTHOR.getInsertUpdateOffset(), author); stmt.setInt(DB_FIELD.STANDARD_ION_RESULT_ID.getInsertUpdateOffset(), standardIonResultId); }
From source file:com.adanac.module.blog.dao.RecordDao.java
public Integer saveOrUpdate(String id, String title, String username, String html, String content) { return execute(new TransactionalOperation<Integer>() { @Override//from w w w.j a v a 2 s .c o m public Integer doInConnection(Connection connection) { String insertSql = "insert into records (title,username,create_date," + "record,content) values (?,?,?,?,?)"; String updateSql = "update records set title=?,username=?,create_date=?,record=?,content=? where id=?"; try { PreparedStatement statement = null; if (StringUtils.isBlank(id)) { statement = connection.prepareStatement(insertSql, Statement.RETURN_GENERATED_KEYS); statement.setString(1, title); statement.setString(2, username); statement.setTimestamp(3, new Timestamp(System.currentTimeMillis())); statement.setString(4, html); statement.setString(5, content); } else { statement = connection.prepareStatement(updateSql); statement.setString(1, title); statement.setString(2, username); statement.setTimestamp(3, new Timestamp(System.currentTimeMillis())); statement.setString(4, html); statement.setString(5, content); statement.setInt(6, Integer.valueOf(id)); } int result = statement.executeUpdate(); if (result > 0 && StringUtils.isBlank(id)) { ResultSet keyResultSet = statement.getGeneratedKeys(); if (keyResultSet.next()) { return keyResultSet.getInt(1); } } if (result > 0) { return Integer.valueOf(id); } } catch (SQLException e) { throw new RuntimeException(e); } return null; } }); }
From source file:dk.netarkivet.common.utils.DBUtils.java
/** * Prepare a statement given a query string and some args. * * NB: the provided connection is not closed. * * @param c a Database connection/* ww w .j a v a2s .c o m*/ * @param query a query string (must not be null or empty) * @param args some args to insert into this query string (must not be null) * @return a prepared statement * @throws SQLException If unable to prepare a statement * @throws ArgumentNotValid If unable to handle type of one the args, or * the arguments are either null or an empty String. */ public static PreparedStatement prepareStatement(Connection c, String query, Object... args) throws SQLException { ArgumentNotValid.checkNotNull(c, "Connection c"); ArgumentNotValid.checkNotNullOrEmpty(query, "String query"); ArgumentNotValid.checkNotNull(args, "Object... args"); PreparedStatement s = c.prepareStatement(query); int i = 1; for (Object arg : args) { if (arg instanceof String) { s.setString(i, (String) arg); } else if (arg instanceof Integer) { s.setInt(i, (Integer) arg); } else if (arg instanceof Long) { s.setLong(i, (Long) arg); } else if (arg instanceof Boolean) { s.setBoolean(i, (Boolean) arg); } else if (arg instanceof Date) { s.setTimestamp(i, new Timestamp(((Date) arg).getTime())); } else { throw new ArgumentNotValid("Cannot handle type '" + arg.getClass().getName() + "'. We can only handle string, " + "int, long, date or boolean args for query: " + query); } i++; } return s; }