List of usage examples for java.sql PreparedStatement setLong
void setLong(int parameterIndex, long x) throws SQLException;
long
value. From source file:com.chenxin.authority.common.logback.DBAppender.java
/** * Add an exception statement either as a batch or execute immediately if * batch updates are not supported.// w w w . jav a 2 s . c o m */ void updateExceptionStatement(PreparedStatement exceptionStatement, String txt, short i, long eventId) throws SQLException { exceptionStatement.setLong(1, eventId); exceptionStatement.setShort(2, i); exceptionStatement.setString(3, txt); if (cnxSupportsBatchUpdates) { exceptionStatement.addBatch(); } else { exceptionStatement.execute(); } }
From source file:org.ulyssis.ipp.snapshot.Event.java
public void setRemoved(Connection connection, boolean removed) throws SQLException { if (!isRemovable()) { assert false; // This is a programming error return;//w w w . j a v a 2 s . c o m } PreparedStatement statement = connection .prepareStatement("UPDATE \"events\" SET \"removed\"=? WHERE \"id\"=?"); statement.setBoolean(1, removed); statement.setLong(2, id); boolean result = statement.execute(); assert (!result); this.removed = true; }
From source file:com.mobilewallet.users.dao.UserQuestionsDAO.java
public int userQuestionsCount(long userId) { int count = 0; Connection connection = null; PreparedStatement cstmt = null; ResultSet rs = null;//from w ww .ja v a2 s. c o m try { connection = dataSource.getConnection(); cstmt = connection.prepareStatement(getUserQuestiosCountQuery); cstmt.setLong(1, userId); rs = cstmt.executeQuery(); if (rs.next()) { count = rs.getInt(1); } } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (rs != null) { rs.close(); } } catch (Exception ex) { } try { if (cstmt != null) { cstmt.close(); } } catch (Exception ex) { } try { if (connection != null) { connection.close(); } } catch (Exception ex) { } } return count; }
From source file:com.carfinance.module.peoplemanage.dao.PeopleManageDao.java
public void peopleroleDoAdd(final long edited_user_id, final long org_id, final String[] role_id) { String sql = "insert into user_role (user_id , role_id , org_id) values (?,?,?)"; try {//from w w w .j av a2s . c om this.getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setLong(1, edited_user_id); ps.setLong(2, Long.valueOf(role_id[i])); ps.setLong(3, org_id); } public int getBatchSize() { return role_id.length;//??labels.length } }); } catch (Exception e) { logger.error(e.getMessage(), e); } }
From source file:com.l2jfree.gameserver.datatables.TradeListTable.java
protected void dataTimerSave(int time) { long timerSave = System.currentTimeMillis() + (long) time * 60 * 60 * 1000; Connection con = null;/*from w w w .j av a 2s .c om*/ try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con .prepareStatement("UPDATE merchant_buylists SET savetimer =? WHERE time =?"); statement.setLong(1, timerSave); statement.setInt(2, time); statement.executeUpdate(); statement.close(); } catch (Exception e) { _log.fatal("TradeController: Could not update Timer save in Buylist"); } finally { L2DatabaseFactory.close(con); } }
From source file:com.l2jfree.gameserver.model.entity.Couple.java
public void marry() { Connection con = null;//w ww . ja va2s. co m try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement; statement = con.prepareStatement("UPDATE couples set maried = ?, weddingDate = ? where id = ?"); statement.setBoolean(1, true); _weddingDate = System.currentTimeMillis(); statement.setLong(2, _weddingDate); statement.setInt(3, _id); statement.execute(); statement.close(); _maried = true; } catch (Exception e) { _log.error("", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.carfinance.module.peoplemanage.dao.PeopleManageDao.java
/** * ?????/* w ww .jav a 2s. co m*/ * @param all_menu_ids * @param role_id */ public void roleMenuDoConfig(final String[] all_menu_ids, final long role_id) { this.deleteRoleMenu(role_id); String sql = "insert into sys_role_menu (role_id , menu_id) values (?,?)"; try { this.getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setLong(1, role_id); ps.setLong(2, Long.valueOf(all_menu_ids[i])); } public int getBatchSize() { return all_menu_ids.length;//??labels.length } }); } catch (Exception e) { logger.error(e.getMessage(), e); } }
From source file:com.hs.mail.imap.dao.MySqlUserDao.java
public long addUser(final User user) { final String sql = "INSERT INTO user (userid, passwd, maxmail_size, forward) VALUES(?, ?, ?, ?)"; KeyHolder keyHolder = new GeneratedKeyHolder(); getJdbcTemplate().update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection con) throws SQLException { PreparedStatement pstmt = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); pstmt.setString(1, user.getUserID()); pstmt.setString(2, user.getPassword()); pstmt.setLong(3, user.getQuota()); pstmt.setString(4, user.getForwardTo()); return pstmt; }/*from ww w . jav a 2 s.com*/ }, keyHolder); long id = keyHolder.getKey().longValue(); user.setID(id); return id; }
From source file:net.sf.l2j.gameserver.model.entity.Couple.java
public void marry() { java.sql.Connection con = null; try {//from w w w . j ava2 s . c om con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement; statement = con.prepareStatement("UPDATE couples set maried = ?, weddingDate = ? where id = ?"); statement.setBoolean(1, true); _weddingDate = Calendar.getInstance(); statement.setLong(2, _weddingDate.getTimeInMillis()); statement.setInt(3, _Id); statement.execute(); statement.close(); _maried = true; } catch (Exception e) { _log.error("", e); } finally { try { con.close(); } catch (Exception e) { } } }
From source file:com.flexive.core.storage.PostgreSQL.PostgreSQLHierarchicalStorage.java
/** * {@inheritDoc}//w w w . ja v a2 s .c om */ @Override public void lockTables(Connection con, long id, int version) throws FxRuntimeException { try { PreparedStatement ps = null; try { String ver = version <= 0 ? "" : " AND VER=?"; ps = con.prepareStatement( "SELECT * FROM " + DatabaseConst.TBL_CONTENT + " WHERE ID=?" + ver + " FOR UPDATE"); ps.setLong(1, id); if (version > 0) ps.setInt(2, version); ps.executeQuery(); ps.close(); ps = con.prepareStatement( "SELECT * FROM " + DatabaseConst.TBL_CONTENT_DATA + " WHERE ID=?" + ver + " FOR UPDATE"); ps.setLong(1, id); if (version > 0) ps.setInt(2, version); ps.executeQuery(); ps.close(); /*ps = con.prepareStatement("SELECT * FROM " + DatabaseConst.TBL_CONTENT_BINARY + " WHERE ID=?" + ver + " FOR UPDATE"); ps.setLong(1, id); if (version > 0) ps.setInt(2, version); ps.executeQuery();*/ //fulltext table uses MyISAM engine and can not be locked } finally { if (ps != null) ps.close(); } if (LOG.isDebugEnabled()) LOG.debug("Locked instances of id #" + id + (version > 0 ? " and version #" + version : " (all versions)")); } catch (SQLException e) { throw new FxDbException(LOG, e, "ex.db.sqlError", e.getMessage()).asRuntimeException(); } }