List of usage examples for java.sql PreparedStatement setLong
void setLong(int parameterIndex, long x) throws SQLException;
long
value. From source file:com.mobilewallet.credits.dao.CreditsDAO.java
public List<WalletHistoryDTO> creditHistory(long userId, int begin, int end) { List<WalletHistoryDTO> list = new ArrayList<WalletHistoryDTO>(); Connection connection = null; PreparedStatement cstmt = null; ResultSet rs = null;/*from w w w . j a v a2 s . c o m*/ try { connection = dataSource.getConnection(); cstmt = connection.prepareStatement(creditHistorQuery); cstmt.setLong(1, userId); cstmt.setInt(2, begin); cstmt.setInt(3, end); rs = cstmt.executeQuery(); WalletHistoryDTO ch = null; while (rs.next()) { ch = new WalletHistoryDTO(); ch.setCid(rs.getLong("wuc_id")); ch.setDesc(rs.getString("wuc_desc")); ch.setAmount(rs.getFloat("wuc_amount")); ch.setcTime(rs.getString("d")); list.add(ch); } } 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 list; }
From source file:com.flexive.core.storage.MySQL.MySQLSequencerStorage.java
/** * {@inheritDoc}// w w w . j av a 2s . c om */ @Override public void setSequencerId(String name, long newId) throws FxApplicationException { Connection con = null; PreparedStatement ps = null; try { con = Database.getDbConnection(); ps = con.prepareStatement("UPDATE " + TBL_SEQUENCE + " SET ID=? WHERE NAME=?"); ps.setLong(1, newId); ps.setString(2, name); ps.executeUpdate(); } catch (SQLException exc) { throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()); } finally { Database.closeObjects(MySQLSequencerStorage.class, con, ps); } }
From source file:com.oic.event.GetProfile.java
@Override public void ActionEvent(JSONObject json, WebSocketListener webSocket) { JSONObject responseJSON = new JSONObject(); if (!validation(json)) { responseJSON.put("status", "1"); webSocket.sendJson(responseJSON); return;// w w w . j av a 2 s . c o m } Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { String sql = "SELECT user.userid, name, avatarid, grade, sex, birth, comment, privategrade, privatesex, privatebirth FROM user JOIN setting ON (user.userid = setting.userid) WHERE user.userid = ?;"; con = DatabaseConnection.getConnection(); ps = con.prepareStatement(sql); ps.setLong(1, Long.parseLong(json.get("userid").toString())); rs = ps.executeQuery(); if (rs.next()) { responseJSON.put("userid", rs.getLong("userid")); responseJSON.put("username", rs.getString("name")); responseJSON.put("avatarid", rs.getInt("avatarid")); if (rs.getString("privategrade").equals("public")) { responseJSON.put("grade", rs.getInt("grade")); } if (rs.getString("privatesex").equals("public")) { responseJSON.put("gender", OicGender.getGender(rs.getString("sex")).toString()); } if (rs.getString("privatebirth").equals("public")) { responseJSON.put("birthday", Tools.convertData(rs.getDate("birth"))); } responseJSON.put("comment", rs.getString("comment")); responseJSON.put("status", 0); } else { responseJSON.put("status", 1); } } catch (SQLException se) { responseJSON.put("status", 1); se.printStackTrace(); } finally { try { rs.close(); } catch (Exception e1) { } try { ps.close(); } catch (Exception e1) { } } webSocket.sendJson(responseJSON); }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaLinkDao.java
/** * Populate the droplet links table./*from w w w .jav a 2 s .c o m*/ * * @param drops */ private void insertDropletLinks(List<Drop> drops) { // List of drop IDs in the drops list List<Long> dropIds = new ArrayList<Long>(); // List of links in a drop Map<Long, Set<Long>> dropletLinksMap = new HashMap<Long, Set<Long>>(); // List of drops and the link that is their original url final List<long[]> originalUrls = new ArrayList<long[]>(); for (Drop drop : drops) { if (drop.getLinks() == null) continue; dropIds.add(drop.getId()); for (Link link : drop.getLinks()) { Set<Long> links = null; if (dropletLinksMap.containsKey(drop.getId())) { links = dropletLinksMap.get(drop.getId()); } else { links = new HashSet<Long>(); dropletLinksMap.put(drop.getId(), links); } // Is this link the original url? if (drop.getOriginalUrl() != null && link.getUrl().equals(drop.getOriginalUrl().getUrl())) { long[] originalUrl = { drop.getId(), link.getId() }; originalUrls.add(originalUrl); } links.add(link.getId()); } } // Find droplet links that already exist in the db String sql = "SELECT droplet_id, link_id FROM droplets_links WHERE droplet_id in (:ids)"; MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("ids", dropIds); List<Map<String, Object>> results = this.namedJdbcTemplate.queryForList(sql, params); // Remove already existing droplet_links from our Set for (Map<String, Object> result : results) { long dropletId = ((Number) result.get("droplet_id")).longValue(); long linkId = ((Number) result.get("link_id")).longValue(); Set<Long> linkSet = dropletLinksMap.get(dropletId); if (linkSet != null) { linkSet.remove(linkId); } } // Insert the remaining items in the set into the db sql = "INSERT INTO droplets_links (droplet_id, link_id) VALUES (?,?)"; final List<long[]> dropletLinksList = new ArrayList<long[]>(); for (Long dropletId : dropletLinksMap.keySet()) { for (Long linkId : dropletLinksMap.get(dropletId)) { long[] dropletLink = { dropletId, linkId }; dropletLinksList.add(dropletLink); } } jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { long[] dropletLink = dropletLinksList.get(i); ps.setLong(1, dropletLink[0]); ps.setLong(2, dropletLink[1]); } public int getBatchSize() { return dropletLinksList.size(); } }); if (originalUrls.size() > 0) { sql = "UPDATE droplets SET original_url = ? WHERE id = ?"; jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { long[] update = originalUrls.get(i); ps.setLong(1, update[1]); ps.setLong(2, update[0]); } public int getBatchSize() { return originalUrls.size(); } }); } }
From source file:com.mobilewallet.credits.dao.CreditsDAO.java
public List<RechargeHistoryDTO> debitHistory(long userId, int begin, int end) { List<RechargeHistoryDTO> list = new ArrayList<RechargeHistoryDTO>(); Connection connection = null; PreparedStatement cstmt = null; ResultSet rs = null;//from www .j av a2s . com try { connection = dataSource.getConnection(); cstmt = connection.prepareStatement(debitHistorQuery); cstmt.setLong(1, userId); cstmt.setInt(2, begin); cstmt.setInt(3, end); rs = cstmt.executeQuery(); RechargeHistoryDTO dht = null; while (rs.next()) { dht = new RechargeHistoryDTO(); dht.setdTime(rs.getString("d")); dht.setAmount(rs.getFloat("wud_amount")); dht.setDesc(rs.getString("wud_desc")); dht.setCode(rs.getString("wud_code")); dht.setDid(rs.getLong("wud_id")); dht.setStatus(rs.getString("wud_status")); list.add(dht); } } 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 list; }
From source file:de.ingrid.importer.udk.strategy.v33.IDCStrategyDefault3_3.java
/** * Also drops all old values (if syslist already exists) ! * @param listId id of syslist/*from w ww .j a v a 2 s. c o m*/ * @param deleteOldValues pass true if all old syslist values should be deleted before adding new ones ! * @param syslistMap_de german entries * @param syslistMap_en english entries * @param defaultEntry_de pass key of GERMAN default entry or -1 if no default entry ! * @param defaultEntry_en pass key of ENGLISH default entry or -1 if no default entry ! * @param syslistMap_descr_de pass null if no GERMAN description available * @param syslistMap_descr_en pass null if no ENGLISH description available * @throws Exception */ protected void writeNewSyslist(int listId, boolean deleteOldValues, LinkedHashMap<Integer, String> syslistMap_de, LinkedHashMap<Integer, String> syslistMap_en, int defaultEntry_de, int defaultEntry_en, LinkedHashMap<Integer, String> syslistMap_descr_de, LinkedHashMap<Integer, String> syslistMap_descr_en) throws Exception { if (syslistMap_descr_de == null) { syslistMap_descr_de = new LinkedHashMap<Integer, String>(); } if (syslistMap_descr_en == null) { syslistMap_descr_en = new LinkedHashMap<Integer, String>(); } if (deleteOldValues) { // clean up, to guarantee no old values ! sqlStr = "DELETE FROM sys_list where lst_id = " + listId; jdbc.executeUpdate(sqlStr); } String psSql = "INSERT INTO sys_list (id, lst_id, entry_id, lang_id, name, maintainable, is_default, description) " + "VALUES (?,?,?,?,?,?,?,?)"; PreparedStatement psInsert = jdbc.prepareStatement(psSql); Iterator<Integer> itr = syslistMap_de.keySet().iterator(); while (itr.hasNext()) { int key = itr.next(); // german version String isDefault = "N"; if (key == defaultEntry_de) { isDefault = "Y"; } psInsert.setLong(1, getNextId()); psInsert.setInt(2, listId); psInsert.setInt(3, key); psInsert.setString(4, "de"); psInsert.setString(5, syslistMap_de.get(key)); psInsert.setInt(6, 0); psInsert.setString(7, isDefault); psInsert.setString(8, syslistMap_descr_de.get(key)); psInsert.executeUpdate(); // english version isDefault = "N"; if (key == defaultEntry_en) { isDefault = "Y"; } psInsert.setLong(1, getNextId()); psInsert.setString(4, "en"); psInsert.setString(5, syslistMap_en.get(key)); psInsert.setString(7, isDefault); psInsert.setString(8, syslistMap_descr_en.get(key)); psInsert.executeUpdate(); } psInsert.close(); }
From source file:iddb.runtime.db.model.dao.impl.mysql.UserDAOImpl.java
@Override public void change_password(User user) { String sql;/*from w w w . ja v a2 s . c o m*/ sql = "update user set password = ?, updated = ? where id = ? limit 1"; Connection conn = null; try { conn = ConnectionFactory.getMasterConnection(); PreparedStatement st = conn.prepareStatement(sql); st.setString(1, user.getPassword()); st.setTimestamp(2, new Timestamp(new Date().getTime())); st.setLong(3, user.getKey()); st.executeUpdate(); } 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:com.sinet.gage.dao.DomainsRepository.java
/** * /* w w w. j a va 2 s . c o m*/ * @param domains */ public void updateDomains(List<Domain> domains) { try { jdbcTemplate.batchUpdate(DOMAINS_FULL_UPDATE_SQL, new BatchPreparedStatementSetter() { public int getBatchSize() { if (domains == null) return 0; return domains.size(); } @Override public void setValues(PreparedStatement ps, int i) throws SQLException { Domain domain = domains.get(i); ps.setObject(1, domain.getGuid()); ps.setString(2, domain.getDomainName()); ps.setString(3, domain.getLoginPrefix()); ps.setLong(4, domain.getFlag()); ps.setString(5, domain.getDomainType()); ps.setLong(6, domain.getParentDomainId()); ps.setString(7, domain.getParentDomainName()); ps.setLong(8, domain.getStateDomainId()); ps.setString(9, domain.getStateDomainName()); ps.setString(10, domain.getLicenseType()); ps.setString(11, domain.getLicensePoolType()); ps.setInt(12, domain.getNoOfLicense()); ps.setBoolean(13, domain.isPilot()); ps.setDate(14, domain.getPilotStartDate()); ps.setDate(15, domain.getPilotEndDate()); ps.setBoolean(16, domain.isFullSubscription()); ps.setObject(17, domain.getSubscriptionStartDate()); ps.setObject(18, domain.getSubscriptionEndDate()); ps.setLong(19, domain.getModifierUserId()); ps.setTimestamp(20, domain.getModifiedDate()); ps.setLong(21, domain.getDomainId()); } }); } catch (Exception e) { log.error("Error in updating Domains", e); } }
From source file:com.flexive.core.storage.genericSQL.GenericBinarySQLOutputStream.java
/** * {@inheritDoc}//from w w w.j a v a 2 s .co m */ @Override public void close() throws IOException { super.close(); try { rcvThread.join(); } catch (InterruptedException e) { LOG.error("Receiving thread got interrupted: " + e.getMessage(), e); } PreparedStatement ps = null; Connection con = null; try { con = Database.getNonTXDataSource(divisionId).getConnection(); ps = con.prepareStatement( "UPDATE " + DatabaseConst.TBL_BINARY_TRANSIT + " SET TFER_DONE=?, BLOBSIZE=? WHERE BKEY=?"); ps.setBoolean(1, true); ps.setLong(2, count); ps.setString(3, handle); if (ps.executeUpdate() != 1) LOG.error("Failed to update binary transit for handle " + handle); } catch (SQLException e) { LOG.error("SQL error marking binary as finished: " + e.getMessage(), e); } finally { Database.closeObjects(GenericBinarySQLOutputStream.class, con, ps); } }
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. jav a 2s . c om*/ }, keyHolder); return keyHolder.getKey().intValue(); }