List of usage examples for java.sql PreparedStatement setLong
void setLong(int parameterIndex, long x) throws SQLException;
long
value. From source file:iddb.runtime.db.model.dao.impl.mysql.PenaltyDAOImpl.java
@Override public void save(Penalty penalty) { String sql;/*from ww w. j a v a 2 s. c o m*/ if (penalty.getKey() == null) { sql = "insert into penalty (playerid, adminid, type, reason, duration, synced, active, created, updated, expires) values (?,?,?,?,?,?,?,?,?,?)"; } else { sql = "update penalty set playerid = ?," + "adminid = ?," + "type = ?," + "reason = ?," + "duration = ?," + "synced = ?," + "active = ?," + "created = ?," + "updated = ?," + "expires = ? where id = ? limit 1"; } Connection conn = null; try { conn = ConnectionFactory.getMasterConnection(); PreparedStatement st = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); st.setLong(1, penalty.getPlayer()); if (penalty.getAdmin() != null) st.setLong(2, penalty.getAdmin()); else st.setNull(2, Types.INTEGER); st.setInt(3, penalty.getType().intValue()); if (penalty.getReason() != null) st.setString(4, penalty.getReason()); else st.setNull(4, Types.VARCHAR); if (penalty.getDuration() == null) penalty.setDuration(0L); st.setLong(5, penalty.getDuration()); st.setBoolean(6, penalty.getSynced()); st.setBoolean(7, penalty.getActive()); if (penalty.getCreated() == null) penalty.setCreated(new Date()); if (penalty.getUpdated() == null) penalty.setUpdated(new Date()); st.setTimestamp(8, new java.sql.Timestamp(penalty.getCreated().getTime())); st.setTimestamp(9, new java.sql.Timestamp(penalty.getUpdated().getTime())); st.setTimestamp(10, new java.sql.Timestamp( DateUtils.addMinutes(penalty.getCreated(), penalty.getDuration().intValue()).getTime())); if (penalty.getKey() != null) st.setLong(11, penalty.getKey()); st.executeUpdate(); if (penalty.getKey() == null) { ResultSet rs = st.getGeneratedKeys(); if (rs != null && rs.next()) { penalty.setKey(rs.getLong(1)); } else { logger.warn("Couldn't get id for penalty player id {}", penalty.getPlayer()); } } } catch (SQLException e) { logger.error("Save: {}", e); } catch (IOException e) { logger.error("Save: {}", e); } finally { try { if (conn != null) conn.close(); } catch (Exception e) { } } }
From source file:org.ensembl.gti.seqstore.database.JdbcSeqStore.java
@Override public long storeGenome(long sessionId, Genome genome) { long id;/*from www. ja va 2 s. c o m*/ try { id = transactionTemplate.execute(new TransactionCallback<Long>() { @Override public Long doInTransaction(TransactionStatus status) { KeyHolder keyHolder = new GeneratedKeyHolder(); template.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection con) throws SQLException { PreparedStatement pst = con.prepareStatement(STORE_GENOME_SQL, new String[] { "name", "assembly", "genebuild", "tax_id", "session_id" }); pst.setString(1, genome.getGenomeName()); pst.setString(2, genome.getAssembly()); pst.setString(3, genome.getGenebuild()); pst.setInt(4, genome.getTaxId()); pst.setLong(5, sessionId); return pst; } }, keyHolder); return (Long) keyHolder.getKey(); } }); } catch (DuplicateKeyException e) { String msg = "Cannot store genome " + genome.toString() + " as it already exists"; log.error(msg, e); throw new DuplicateSeqObjException(msg, e); } log.debug("New genome " + id); return id; }
From source file:com.flexive.core.storage.genericSQL.GenericSQLFulltextIndexer.java
/** * {@inheritDoc}//www .j a v a 2 s .c o m */ @Override public void removeAllVersions() { if (pk == null) { LOG.warn("Tried to remove all fulltext versions with no pk provided!"); return; } PreparedStatement ps = null; try { ps = con.prepareStatement(CONTENT_DATA_FT_REMOVE); ps.setLong(1, pk.getId()); ps.executeUpdate(); } catch (SQLException e) { LOG.error(e); } finally { try { if (ps != null) ps.close(); } catch (SQLException e) { LOG.error(e); } } }
From source file:com.flexive.core.storage.genericSQL.GenericSQLFulltextIndexer.java
/** * {@inheritDoc}/*from ww w . j av a 2 s . c o m*/ */ @Override public void setLanguage(long assignmentId, long lang) { PreparedStatement ps = null; try { ps = con.prepareStatement(CONTENT_FULLTEXT_SET_LANG); ps.setLong(1, lang); ps.setLong(2, assignmentId); ps.executeUpdate(); } catch (SQLException e) { LOG.error(e); } finally { try { if (ps != null) ps.close(); } catch (SQLException e) { LOG.error(e); } } }
From source file:com.flexive.core.storage.genericSQL.GenericSQLFulltextIndexer.java
/** * {@inheritDoc}//from www . j av a 2 s. co m */ @Override public void removeType(long typeId) { PreparedStatement ps = null; try { ps = con.prepareStatement(CONTENT_DATA_FT_REMOVE_TYPE); ps.setLong(1, typeId); ps.executeUpdate(); } catch (SQLException e) { LOG.error(e); } finally { try { if (ps != null) ps.close(); } catch (SQLException e) { LOG.error(e); } } }
From source file:com.liferay.portal.upgrade.util.Table.java
public void setColumn(PreparedStatement ps, int index, Integer type, String value) throws Exception { int t = type.intValue(); int paramIndex = index + 1; if (t == Types.BIGINT) { ps.setLong(paramIndex, GetterUtil.getLong(value)); } else if (t == Types.BOOLEAN) { ps.setBoolean(paramIndex, GetterUtil.getBoolean(value)); } else if ((t == Types.CLOB) || (t == Types.VARCHAR)) { value = StringUtil.replace(value, SAFE_CHARS[1], SAFE_CHARS[0]); ps.setString(paramIndex, value); } else if (t == Types.DOUBLE) { ps.setDouble(paramIndex, GetterUtil.getDouble(value)); } else if (t == Types.FLOAT) { ps.setFloat(paramIndex, GetterUtil.getFloat(value)); } else if (t == Types.INTEGER) { ps.setInt(paramIndex, GetterUtil.getInteger(value)); } else if (t == Types.SMALLINT) { ps.setShort(paramIndex, GetterUtil.getShort(value)); } else if (t == Types.TIMESTAMP) { if (StringPool.NULL.equals(value)) { ps.setTimestamp(paramIndex, null); } else {//from w w w . j a v a 2 s . c o m DateFormat df = DateUtil.getISOFormat(); ps.setTimestamp(paramIndex, new Timestamp(df.parse(value).getTime())); } } else { throw new UpgradeException("Upgrade code using unsupported class type " + type); } }
From source file:iddb.runtime.db.model.dao.impl.mysql.PenaltyDAOImpl.java
@Override public void disable(List<Penalty> list) { String sql = "update penalty set active = ? where id = ?"; Connection conn = null;//from w w w .j a va2 s . co m try { conn = ConnectionFactory.getMasterConnection(); PreparedStatement st = conn.prepareStatement(sql); for (Penalty p : list) { st.setBoolean(1, false); st.setLong(2, p.getKey()); st.addBatch(); } st.executeBatch(); } catch (SQLException e) { logger.error("disable: {}", e); } catch (IOException e) { logger.error("disable: {}", e); } finally { try { if (conn != null) conn.close(); } catch (Exception e) { } } }
From source file:com.flexive.core.storage.genericSQL.GenericSQLFulltextIndexer.java
/** * {@inheritDoc}//w w w .j a v a2 s . com */ @Override public void changeLanguage(long assignmentId, long oldLanguage, long newLanguage) { PreparedStatement ps = null; try { ps = con.prepareStatement(CONTENT_FULLTEXT_CHANGE_LANG); ps.setLong(1, oldLanguage); ps.setLong(2, newLanguage); ps.setLong(3, assignmentId); ps.executeUpdate(); } catch (SQLException e) { LOG.error(e); } finally { try { if (ps != null) ps.close(); } catch (SQLException e) { LOG.error(e); } } }
From source file:com.softberries.klerk.dao.AddressDao.java
public void update(Address c, QueryRunner run, Connection conn) throws SQLException { PreparedStatement st = conn.prepareStatement(SQL_UPDATE_ADDRESS); st.setString(1, c.getCountry());/*from w w w .j a v a2s. co m*/ st.setString(2, c.getCity()); st.setString(3, c.getStreet()); st.setString(4, c.getPostCode()); st.setString(5, c.getHouseNumber()); st.setString(6, c.getFlatNumber()); st.setString(7, c.getNotes()); st.setBoolean(8, c.isMain()); if (c.getPerson_id() == null && c.getCompany_id() == null) { throw new SQLException("Either Person or Company needs to be specified"); } if (c.getPerson_id().longValue() != 0) { st.setLong(9, c.getPerson_id()); } else { st.setNull(9, java.sql.Types.NUMERIC); } if (c.getCompany_id().longValue() != 0) { st.setLong(10, c.getCompany_id()); } else { st.setNull(10, java.sql.Types.NUMERIC); } st.setLong(11, c.getId()); // run the query int i = st.executeUpdate(); System.out.println("i: " + i); if (i == -1) { System.out.println("db error : " + SQL_UPDATE_ADDRESS); } }
From source file:com.amazonbird.announce.ProductMgrImpl.java
public int getViewCountForProduct(long productId) { ///*from ww w . j a v a2 s . co m*/ Connection connection = null; PreparedStatement ps = null; ResultSet rs = null; int count = 0; try { connection = dbMgr.getConnection(); ps = connection.prepareStatement( "select count(*) from announcement, product, click where click.announcementid = announcement.id and announcement.productid = product.id and product.id = ?"); ps.setLong(1, productId); rs = ps.executeQuery(); if (rs.next()) { count = rs.getInt(1); } logger.debug(DBConstants.QUERY_EXECUTION_SUCC + ps.toString()); } catch (SQLException ex) { logger.error(DBConstants.QUERY_EXECUTION_FAIL + ps.toString(), ex); } finally { dbMgr.closeResources(connection, ps, rs); } return count; }