List of usage examples for java.sql PreparedStatement setLong
void setLong(int parameterIndex, long x) throws SQLException;
long
value. 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 ww w. j ava 2 s. 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.l2jfree.gameserver.instancemanager.ItemsOnGroundManager.java
private void load() { // If SaveDroppedItem is false, may want to delete all items previously stored to avoid add old items on reactivate if (!Config.SAVE_DROPPED_ITEM && Config.CLEAR_DROPPED_ITEM_TABLE) emptyTable();//from w w w . j a v a 2 s.com if (!Config.SAVE_DROPPED_ITEM) return; // if DestroyPlayerDroppedItem was previously false, items curently protected will be added to ItemsAutoDestroy if (Config.DESTROY_DROPPED_PLAYER_ITEM) { Connection con = null; try { String str = null; if (!Config.DESTROY_EQUIPABLE_PLAYER_ITEM) // Recycle misc. items only str = "UPDATE itemsonground SET drop_time=? WHERE drop_time=-1 AND equipable=0"; else if (Config.DESTROY_EQUIPABLE_PLAYER_ITEM) // Recycle all items including equipable str = "UPDATE itemsonground SET drop_time=? WHERE drop_time=-1"; con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement(str); statement.setLong(1, System.currentTimeMillis()); statement.execute(); statement.close(); } catch (Exception e) { _log.fatal("error while updating table ItemsOnGround " + e, e); } finally { L2DatabaseFactory.close(con); } } // Add items to world Connection con = null; try { try { con = L2DatabaseFactory.getInstance().getConnection(con); Statement s = con.createStatement(); ResultSet result; int count = 0; result = s.executeQuery( "SELECT object_id,item_id,count,enchant_level,x,y,z,drop_time,equipable FROM itemsonground"); while (result.next()) { L2ItemInstance item = new L2ItemInstance(result.getInt(1), result.getInt(2)); L2World.getInstance().storeObject(item); item.setCount(result.getLong(3)); item.setEnchantLevel(result.getInt(4)); item.getPosition().setXYZ(result.getInt(5), result.getInt(6), result.getInt(7)); item.setDropTime(result.getLong(8)); if (result.getLong(8) == -1) item.setProtected(true); else item.setProtected(false); L2World.getInstance().addVisibleObject(item); _items.add(item); count++; // Add to ItemsAutoDestroy only items not protected if (result.getLong(8) > -1) { ItemsAutoDestroyManager.tryAddItem(item); } } result.close(); s.close(); if (count > 0) _log.info("ItemsOnGroundManager: restored " + count + " items."); else _log.info("Initializing ItemsOnGroundManager."); } catch (Exception e) { _log.fatal("error while loading ItemsOnGround " + e, e); } } finally { L2DatabaseFactory.close(con); } if (Config.EMPTY_DROPPED_ITEM_TABLE_AFTER_LOAD) emptyTable(); }
From source file:eionet.cr.dao.virtuoso.VirtuosoSpoBinaryDAO.java
public void add(SpoBinaryDTO dto) throws DAOException { if (dto == null) { throw new IllegalArgumentException("DTO object must not be null"); }/* w w w . j a v a 2s . c om*/ Connection conn = null; PreparedStatement stmt = null; try { conn = getSQLConnection(); stmt = conn.prepareStatement(SQL_ADD); stmt.setLong(1, dto.getSubjectHash()); String lang = dto.getLanguage(); stmt.setString(2, lang == null ? "" : lang); String contentType = dto.getContentType(); stmt.setString(3, contentType == null ? "" : contentType); stmt.setString(4, dto.isMustEmbed() ? "Y" : "N"); stmt.executeUpdate(); } catch (SQLException sqle) { throw new DAOException(sqle.getMessage(), sqle); } finally { SQLUtil.close(stmt); SQLUtil.close(conn); } }
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 a2 s.co 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; }
From source file:henu.dao.impl.CaclDaoImpl.java
@Override public boolean recordCaclUser(long cid, long users[]) { int result = 0; try {// www. j a v a 2 s . co m String sql = "insert into uc (cid, uid) values(?,?)"; SqlDB.getConnection().setAutoCommit(false); PreparedStatement ps = SqlDB.executePreparedStatement(sql); for (int i = 0; i < users.length; i++) { ps.setLong(1, cid); ps.setLong(2, users[i]); ps.addBatch(); } result = ps.executeBatch().length; ps.clearBatch(); SqlDB.close(); } catch (SQLException ex) { } return result == users.length; }
From source file:com.hs.mail.imap.dao.MySqlUserDao.java
public long addAlias(final Alias alias) { final String sql = "INSERT INTO alias (alias, deliver_to) 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, alias.getAlias()); pstmt.setLong(2, alias.getDeliverTo()); return pstmt; }//from w ww . ja va2 s . c o m }, keyHolder); long id = keyHolder.getKey().longValue(); alias.setID(id); return id; }
From source file:com.senior.g40.service.UserService.java
public boolean createAccount(String firstName, String lastName, long personalId, String phoneNumber, String address1, String address2, int age, char gender, String username, String password, char userType) { try {/* w w w. j ava2s . c om*/ Connection conn = ConnectionBuilder.getConnection(); String sqlCmd = "INSERT INTO `profile` " + "(`firstName`, `lastName`, `personalId`, `phone`, `address1`, `address2`, `age`, `gender`) " + "VALUES (?, ?, ?, ?, ?, ?, ?, ?);"; PreparedStatement pstm = conn.prepareStatement(sqlCmd); pstm.setString(1, firstName); pstm.setString(2, lastName); pstm.setLong(3, personalId); pstm.setString(4, phoneNumber); pstm.setString(5, address1); pstm.setString(6, address2); pstm.setInt(7, age); pstm.setString(8, String.valueOf(gender)); if (pstm.executeUpdate() != 0) { conn.close(); createUser(username, password, userType); return true; } conn.close(); } catch (SQLException ex) { Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); } return false; }
From source file:com.flexive.core.storage.MySQL.MySQLTreeStorage.java
/** * {@inheritDoc}/*from ww w. j a va2 s. c o m*/ */ @Override public List<String> getLabels(Connection con, FxTreeMode mode, long labelPropertyId, FxLanguage language, boolean stripNodeInfos, long... nodeIds) throws FxApplicationException { List<String> ret = new ArrayList<String>(nodeIds.length); if (nodeIds.length == 0) return ret; PreparedStatement ps = null; ResultSet rs; try { ps = con.prepareStatement("SELECT tree_FTEXT1024_Chain(?,?,?,?)"); ps.setInt(2, (int) language.getId()); ps.setLong(3, labelPropertyId); ps.setBoolean(4, mode == FxTreeMode.Live); for (long id : nodeIds) { ps.setLong(1, id); try { rs = ps.executeQuery(); if (rs != null && rs.next()) { final String path = rs.getString(1); if (!StringUtils.isEmpty(path)) ret.add(stripNodeInfos ? stripNodeInfos(path) : path); else addUnknownNodeId(ret, id); } else addUnknownNodeId(ret, id); } catch (SQLException e) { if ("22001".equals(e.getSQLState())) { //invalid node id in MySQL addUnknownNodeId(ret, id); } else throw e; } } return ret; } catch (SQLException e) { throw new FxLoadException(LOG, e, "ex.db.sqlError", e.getMessage()); } finally { try { if (ps != null) ps.close(); } catch (Exception e) { //ignore } } }
From source file:com.mobilewallet.users.dao.NotificationsDAO.java
public String getNotificationStatusOfUser(long userId) { Connection connection = null; PreparedStatement cstmt = null; ResultSet rs = null;//from ww w . j a v a 2 s. c o m String s = null; try { connection = dataSource.getConnection(); cstmt = connection.prepareStatement(getUserNotificationsQuery); cstmt.setLong(1, userId); rs = cstmt.executeQuery(); if (rs.next()) { s = rs.getString("u_notify"); } } 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 s; }
From source file:com.jagornet.dhcp.db.JdbcIaAddressDAO.java
public List<IaAddress> findAllByIdentityAssocId(final long identityAssocId) { return getJdbcTemplate().query("select * from iaaddress where identityassoc_id = ? order by ipaddress", new PreparedStatementSetter() { @Override//from w w w .j a va 2 s .c om public void setValues(PreparedStatement ps) throws SQLException { ps.setLong(1, identityAssocId); } }, new IaAddrRowMapper()); }