List of usage examples for java.sql PreparedStatement setLong
void setLong(int parameterIndex, long x) throws SQLException;
long
value. From source file:com.keybox.manage.db.ProfileDB.java
/** * updates profile/* ww w.ja v a 2 s .com*/ * * @param profile profile object */ public static void updateProfile(Profile profile) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement("update profiles set nm=?, desc=? where id=?"); stmt.setString(1, profile.getNm()); stmt.setString(2, profile.getDesc()); stmt.setLong(3, profile.getId()); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } finally { DBUtils.closeConn(con); } }
From source file:com.keybox.manage.db.SystemStatusDB.java
/** * updates the status table to keep track of key placement status * * @param con DB connection * @param hostSystem systems for authorized_keys replacement * @param userId user id/* ww w .j a v a 2s .co m*/ */ public static void updateSystemStatus(Connection con, HostSystem hostSystem, Long userId) { try { PreparedStatement stmt = con.prepareStatement("update status set status_cd=? where id=? and user_id=?"); stmt.setString(1, hostSystem.getStatusCd()); stmt.setLong(2, hostSystem.getId()); stmt.setLong(3, userId); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } }
From source file:com.tethrnet.manage.db.SessionAuditDB.java
/** * returns a list of terminal sessions for session id * * @param sessionId session id/* ww w. j ava 2 s . com*/ * @return terminal sessions with host information */ public static SessionAudit getSessionsTerminals(Long sessionId) { //get db connection Connection con = null; SessionAudit sessionAudit = new SessionAudit(); String sql = "select * from session_log, users where users.id= session_log.user_id and session_log.id = ? "; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); stmt.setLong(1, sessionId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { sessionAudit.setId(rs.getLong("session_log.id")); sessionAudit.setSessionTm(rs.getTimestamp("session_tm")); sessionAudit.setUser(UserDB.getUser(con, rs.getLong("user_id"))); sessionAudit.setHostSystemList(getHostSystemsForSession(con, sessionId)); } DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } //close db connection DBUtils.closeConn(con); return sessionAudit; }
From source file:com.keybox.manage.db.SessionAuditDB.java
/** * returns a list of terminal sessions for session id * * @param sessionId session id//ww w . ja va 2 s.c o m * @return terminal sessions with host information */ public static SessionAudit getSessionsTerminals(Long sessionId) { //get db connection Connection con = null; SessionAudit sessionAudit = new SessionAudit(); String sql = "select * from session_log, users where users.id= session_log.user_id and session_log.id = ? "; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); stmt.setLong(1, sessionId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { sessionAudit.setId(rs.getLong("session_log.id")); sessionAudit.setSessionTm(rs.getTimestamp(SESSION_TM)); sessionAudit.setUser(UserDB.getUser(con, rs.getLong(USER_ID))); sessionAudit.setHostSystemList(getHostSystemsForSession(con, sessionId)); } DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } //close db connection DBUtils.closeConn(con); return sessionAudit; }
From source file:ca.qc.adinfo.rouge.social.db.SocialDb.java
public static boolean addFriend(DBManager dbManager, long userId, long friendId) { Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null;/*from w ww .j a v a 2 s.c om*/ String sql = null; sql = "INSERT INTO rouge_social_friends (`user_id`, `friend_user_id`) VALUES (?, ?)"; try { connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); stmt.setLong(1, userId); stmt.setLong(2, friendId); int ret = stmt.executeUpdate(); if (ret < 1) { return false; } stmt.setLong(1, friendId); stmt.setLong(2, userId); ret = stmt.executeUpdate(); return (ret > 0); } catch (SQLException e) { log.error(stmt); log.error(e); return false; } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(connection); } }
From source file:com.tethrnet.manage.db.UserDB.java
/** * returns user base on id/*w w w. j a va 2s . c om*/ * @param con DB connection * @param userId user id * @return user object */ public static User getUser(Connection con, Long userId) { User user = null; try { PreparedStatement stmt = con.prepareStatement("select * from users where id=?"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { user = new User(); user.setId(rs.getLong("id")); user.setEmail(rs.getString("email")); user.setUsername(rs.getString("username")); user.setPassword(rs.getString("password")); user.setAuthType(rs.getString("auth_type")); user.setUserType(rs.getString("user_type")); user.setSalt(rs.getString("salt")); user.setProfileList(UserProfileDB.getProfilesByUser(con, userId)); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return user; }
From source file:com.keybox.manage.db.AuthDB.java
/** * returns the shared secret based on user id * * @param userId user id/*from w ww .ja va 2s . c om*/ * @return auth object */ public static String getSharedSecret(Long userId) { String sharedSecret = null; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement("select * from users where id like ?"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); if (rs.next()) { sharedSecret = EncryptionUtil.decrypt(rs.getString("otp_secret")); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); return sharedSecret; }
From source file:com.keybox.manage.db.UserDB.java
/** * deletes user//from ww w . j a va 2 s . c o m * @param userId user id */ public static void disableUser(Long userId) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement("update users set enabled=false where id=?"); stmt.setLong(1, userId); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); }
From source file:com.keybox.manage.db.ProfileSystemsDB.java
/** * adds a host system to profile// w ww . j av a2s . c o m * * @param profileId profile id * @param systemId host system id */ public static void addSystemToProfile(Long profileId, Long systemId) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con .prepareStatement("insert into system_map (profile_id, system_id) values (?,?)"); stmt.setLong(1, profileId); stmt.setLong(2, systemId); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { e.printStackTrace(); } DBUtils.closeConn(con); }
From source file:com.keybox.manage.db.UserDB.java
/** * resets shared secret for user//w ww.j a v a 2 s.c om * @param userId user id */ public static void resetSharedSecret(Long userId) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement("update users set otp_secret=null where id=?"); stmt.setLong(1, userId); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); }