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.UserDB.java
/** * returns user base on id// w ww.j a va2 s .co m * @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.setFirstNm(rs.getString(FIRST_NM)); user.setLastNm(rs.getString(LAST_NM)); 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:ca.qc.adinfo.rouge.mail.db.MailDb.java
public static boolean setMailAsRead(DBManager dbManager, long mailId) { Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null;//from ww w .j a v a2s . c o m String sql = null; sql = "UPDATE rouge_mail SET `status` = ? WHERE `id` = ? "; try { connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); stmt.setString(1, "rea"); stmt.setLong(2, mailId); int 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:ca.qc.adinfo.rouge.mail.db.MailDb.java
public static boolean deleteMail(DBManager dbManager, long mailId) { Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null;//from ww w. j a v a 2 s . co m String sql = null; sql = "UPDATE rouge_mail SET `status` = ? WHERE `id` = ? "; try { connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); stmt.setString(1, "del"); stmt.setLong(2, mailId); int 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:ca.qc.adinfo.rouge.mail.db.MailDb.java
public static boolean sendMail(DBManager dbManager, long fromId, long toId, RougeObject content) { Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null;//from w w w.j a v a 2 s . co m String sql = null; sql = "INSERT INTO rouge_mail (`from`, `to`, `content`, `status`, `time_sent`) " + "VALUES (?, ?, ?, ?, ?)"; try { connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); stmt.setLong(1, fromId); stmt.setLong(2, toId); stmt.setString(3, content.toJSON().toString()); stmt.setString(4, "unr"); stmt.setTimestamp(5, new Timestamp(System.currentTimeMillis())); int 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.flexive.core.LifeCycleInfoImpl.java
/** * Update a lifyecycle info/*from www. j ava2 s.com*/ * * @param ps prepared statement * @param modificatorColumn column index of the modified by user reference * @param modificationTimeColumn column index of the modified by timestamp * @throws java.sql.SQLException if a column could not be set */ public static void updateLifeCycleInfo(PreparedStatement ps, int modificatorColumn, int modificationTimeColumn) throws SQLException { final UserTicket ticket = FxContext.getUserTicket(); final long ts = System.currentTimeMillis(); ps.setLong(modificatorColumn, ticket.getUserId()); ps.setLong(modificationTimeColumn, ts); }
From source file:ch.newscron.registration.UserRegistration.java
public static void registerUserByShortURL(String name, String lastName, String email, long shortUrlId) { Connection connection = null; PreparedStatement query = null; ResultSet rs = null;//from w w w.jav a 2 s .c o m try { connection = connect(); query = connection .prepareStatement("INSERT INTO User (name, lastName, email, campaignId) VALUES (?, ?, ?, ?)"); query.setString(1, name); query.setString(2, lastName); query.setString(3, email); query.setLong(4, shortUrlId); query.executeUpdate(); } catch (Exception ex) { Logger.getLogger(UserRegistration.class.getName()).log(Level.SEVERE, null, ex); } finally { disconnect(connection, query, rs); } }
From source file:ca.qc.adinfo.rouge.social.db.SocialDb.java
public static boolean deleteFriend(DBManager dbManager, long userId, long friendId) { Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null;/*from w w w . ja v a2 s . co m*/ String sql = null; sql = "DELETE FROM rouge_social_friends " + "WHERE (`user_id` = ? AND `friend_user_id` = ?) " + "OR (`user_id` = ? AND `friend_user_id` = ?)"; try { connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); stmt.setLong(1, userId); stmt.setLong(2, friendId); stmt.setLong(3, friendId); stmt.setLong(4, userId); int 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.keybox.manage.db.ProfileSystemsDB.java
/** * returns a list of system ids for a given profile * * @param con DB con/*from w ww. j a v a 2s . co m*/ * @param profileId profile id * @return list of host systems */ public static List<Long> getSystemIdsByProfile(Connection con, Long profileId) { List<Long> systemIdList = new ArrayList<Long>(); try { PreparedStatement stmt = con.prepareStatement( "select * from system s, system_map m where s.id=m.system_id and m.profile_id=? order by display_nm asc"); stmt.setLong(1, profileId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { systemIdList.add(rs.getLong("id")); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { e.printStackTrace(); } return systemIdList; }
From source file:com.sf.ddao.factory.param.ParameterHelper.java
public static void bind(PreparedStatement preparedStatement, int idx, Object param, Class<?> clazz, Context context) throws SQLException { if (clazz == Integer.class || clazz == Integer.TYPE) { preparedStatement.setInt(idx, (Integer) param); } else if (clazz == String.class) { preparedStatement.setString(idx, (String) param); } else if (clazz == Long.class || clazz == Long.TYPE) { preparedStatement.setLong(idx, (Long) param); } else if (clazz == Boolean.class || clazz == Boolean.TYPE) { preparedStatement.setBoolean(idx, (Boolean) param); } else if (BigInteger.class.isAssignableFrom(clazz)) { BigInteger bi = (BigInteger) param; preparedStatement.setBigDecimal(idx, new BigDecimal(bi)); } else if (Timestamp.class.isAssignableFrom(clazz)) { preparedStatement.setTimestamp(idx, (Timestamp) param); } else if (Date.class.isAssignableFrom(clazz)) { if (!java.sql.Date.class.isAssignableFrom(clazz)) { param = new java.sql.Date(((Date) param).getTime()); }/*from w w w . java 2s . c om*/ preparedStatement.setDate(idx, (java.sql.Date) param); } else if (BoundParameter.class.isAssignableFrom(clazz)) { ((BoundParameter) param).bindParam(preparedStatement, idx, context); } else { throw new SQLException("Unimplemented type mapping for " + clazz); } }
From source file:com.tethrnet.manage.db.SessionAuditDB.java
/** * returns terminal logs for user session for host system * * @param con DB connection/* w w w . j a v a 2 s . c o m*/ * @param sessionId session id * @return session output for session */ public static List<HostSystem> getHostSystemsForSession(Connection con, Long sessionId) { List<HostSystem> hostSystemList = new ArrayList<HostSystem>(); try { PreparedStatement stmt = con.prepareStatement( "select distinct instance_id, system_id from terminal_log where session_id=?"); stmt.setLong(1, sessionId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { HostSystem hostSystem = SystemDB.getSystem(con, rs.getLong("system_id")); hostSystem.setInstanceId(rs.getInt("instance_id")); hostSystemList.add(hostSystem); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception ex) { log.error(ex.toString(), ex); } return hostSystemList; }