List of usage examples for java.sql PreparedStatement setLong
void setLong(int parameterIndex, long x) throws SQLException;
long
value. From source file:ch.newscron.referral.ReferralManager.java
/** * Calls the database to query for all rows in ShortURL table of database in relation to customerId * @param customerId a long representing the unique customer id * @return a List of CustomerShortURL objects, consisting of the shortURL table entries corresponding to the given customerId *//*from w ww . j a va2 s.com*/ public static List<CustomerShortURL> getCustomerShortURLs(long customerId) { Connection connection = null; PreparedStatement query = null; ResultSet rs = null; try { connection = connect(); query = connection.prepareStatement("SELECT * FROM ShortURL WHERE custId = ?"); query.setLong(1, customerId); rs = query.executeQuery(); List<CustomerShortURL> shortURLList = parseResultSet(rs); return shortURLList; } catch (Exception ex) { Logger.getLogger(ReferralManager.class.getName()).log(Level.SEVERE, null, ex); } finally { disconnect(connection, query, rs); } return null; }
From source file:com.tethrnet.manage.db.SystemStatusDB.java
/** * returns key placement status of system * * @param systemId system id/*from w w w . ja v a2 s .c o m*/ * @param userId user id */ public static HostSystem getSystemStatus(Long systemId, Long userId) { Connection con = null; HostSystem hostSystem = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement("select * from status where id=? and user_id=?"); stmt.setLong(1, systemId); stmt.setLong(2, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { hostSystem = SystemDB.getSystem(con, rs.getLong("id")); hostSystem.setStatusCd(rs.getString("status_cd")); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); return hostSystem; }
From source file:com.keybox.manage.db.SystemStatusDB.java
/** * returns key placement status of system * * @param systemId system id/*from w w w . jav a 2 s .c om*/ * @param userId user id */ public static HostSystem getSystemStatus(Long systemId, Long userId) { Connection con = null; HostSystem hostSystem = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement("select * from status where id=? and user_id=?"); stmt.setLong(1, systemId); stmt.setLong(2, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { hostSystem = SystemDB.getSystem(con, rs.getLong("id")); hostSystem.setStatusCd(rs.getString(STATUS_CD)); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); return hostSystem; }
From source file:com.tethrnet.manage.db.SystemStatusDB.java
/** * returns all key placement statuses/*from ww w . j a v a2 s .c o m*/ * * @param con DB connection object * @param userId user id */ private static List<HostSystem> getAllSystemStatus(Connection con, Long userId) { List<HostSystem> hostSystemList = new ArrayList<HostSystem>(); try { PreparedStatement stmt = con.prepareStatement("select * from status where user_id=? order by id asc"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { HostSystem hostSystem = SystemDB.getSystem(con, rs.getLong("id")); hostSystem.setStatusCd(rs.getString("status_cd")); hostSystemList.add(hostSystem); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return hostSystemList; }
From source file:com.keybox.manage.db.SystemStatusDB.java
/** * returns all key placement statuses/*from w ww .ja v a 2s .com*/ * * @param con DB connection object * @param userId user id */ private static List<HostSystem> getAllSystemStatus(Connection con, Long userId) { List<HostSystem> hostSystemList = new ArrayList<>(); try { PreparedStatement stmt = con.prepareStatement("select * from status where user_id=? order by id asc"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { HostSystem hostSystem = SystemDB.getSystem(con, rs.getLong("id")); hostSystem.setStatusCd(rs.getString(STATUS_CD)); hostSystemList.add(hostSystem); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return hostSystemList; }
From source file:alfio.manager.UploadedResourceManager.java
private static void setFileValues(PreparedStatement ps, LobCreator lobCreator, UploadBase64FileModification file, int baseIndex) throws SQLException { ps.setString(1, file.getName());/*w ww .j av a 2 s .c o m*/ ps.setLong(baseIndex + 1, file.getFile().length); lobCreator.setBlobAsBytes(ps, baseIndex + 2, file.getFile()); ps.setString(baseIndex + 3, file.getType()); ps.setString(baseIndex + 4, Json.GSON.toJson(getAttributes(file))); }
From source file:com.webbfontaine.valuewebb.gtns.TTGTNSSynchronizer.java
private static void updateTTFlag(TtGen ttGen) { Connection conn = null;/*from ww w .j a va 2 s .c o m*/ PreparedStatement ps = null; try { conn = Utils.getSQLConnection(); conn.setAutoCommit(false); ps = conn.prepareStatement(UPDATE_TT_SQL); ps.setLong(1, ttGen.getId()); ps.executeUpdate(); conn.commit(); } catch (SQLException e) { LOGGER.error("Error in updating GCNet Submission Flag for TT with id {0}, error {1}", ttGen.getId(), e); } finally { DBUtils.closeResource(ps); DBUtils.closeResource(conn); } }
From source file:com.keybox.manage.db.SystemStatusDB.java
/** * inserts into the status table to keep track of key placement status * * @param con DB connection object * @param hostSystem systems for authorized_keys replacement * @param userId user id//from w w w . ja va2 s . com */ private static void insertSystemStatus(Connection con, HostSystem hostSystem, Long userId) { try { PreparedStatement stmt = con .prepareStatement("insert into status (id, status_cd, user_id) values (?,?,?)"); stmt.setLong(1, hostSystem.getId()); stmt.setString(2, hostSystem.getStatusCd()); stmt.setLong(3, userId); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } }
From source file:ca.qc.adinfo.rouge.social.db.SocialDb.java
public static Collection<Long> getFriends(DBManager dbManager, long userId) { Collection<Long> friends = new ArrayList<Long>(); Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null;// ww w. j av a 2s.co m String sql = "SELECT `friend_user_id` FROM rouge_social_friends WHERE `user_id` = ? "; try { connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); stmt.setLong(1, userId); rs = stmt.executeQuery(); while (rs.next()) { friends.add(rs.getLong("friend_user_id")); } return friends; } catch (SQLException e) { log.error(stmt); log.error(e); return null; } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(connection); } }
From source file:com.keybox.manage.db.ProfileSystemsDB.java
/** * deletes all systems for a given profile * * @param profileId profile id//from w w w . j av a 2 s . c o m */ public static void deleteAllSystemsFromProfile(Long profileId) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement("delete from system_map where profile_id=?"); stmt.setLong(1, profileId); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { e.printStackTrace(); } DBUtils.closeConn(con); }