List of usage examples for java.sql PreparedStatement setString
void setString(int parameterIndex, String x) throws SQLException;
String
value. From source file:com.tethrnet.manage.db.UserDB.java
/** * updates existing user//from w w w. j a v a2 s. c o m * @param user user object */ public static void updateUserNoCredentials(User user) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con .prepareStatement("update users set email=?, username=?, user_type=? where id=?"); stmt.setString(1, user.getEmail()); stmt.setString(2, user.getUsername()); stmt.setString(3, user.getUserType()); stmt.setLong(4, user.getId()); stmt.execute(); DBUtils.closeStmt(stmt); if (User.ADMINISTRATOR.equals(user.getUserType())) { PublicKeyDB.deleteUnassignedKeysByUser(con, user.getId()); } } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); }
From source file:fll.db.NonNumericNominees.java
/** * Get all nominees in the specified category. * //from w w w . ja v a2 s .c om * @throws SQLException */ public static Set<Integer> getNominees(final Connection connection, final int tournamentId, final String category) throws SQLException { final Set<Integer> result = new HashSet<>(); PreparedStatement get = null; ResultSet rs = null; try { get = connection.prepareStatement( "SELECT DISTINCT team_number FROM non_numeric_nominees" + " WHERE tournament = ?" // + " AND category = ?"); get.setInt(1, tournamentId); get.setString(2, category); rs = get.executeQuery(); while (rs.next()) { final int team = rs.getInt(1); result.add(team); } } finally { SQLFunctions.close(rs); SQLFunctions.close(get); } return result; }
From source file:ca.qc.adinfo.rouge.achievement.db.AchievementDb.java
public static boolean createAchievement(DBManager dbManager, String key, String name, int pointValue, double total) { Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null;//from ww w .j a v a2 s.co m String sql = null; sql = "INSERT INTO rouge_achievements (`key`, `name`, `point_value`, `total`) " + " VALUES (?, ?, ?, ?);"; try { connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); stmt.setString(1, key); stmt.setString(2, name); stmt.setInt(3, pointValue); stmt.setDouble(4, total); 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.AuthDB.java
/** * returns user id based on auth token// w ww.j a v a 2 s . c o m * * @param authToken auth token * @param con DB connection * @return user */ public static User getUserByAuthToken(Connection con, String authToken) { User user = null; try { PreparedStatement stmt = con .prepareStatement("select * from users where enabled=true and auth_token like ?"); stmt.setString(1, authToken); ResultSet rs = stmt.executeQuery(); if (rs.next()) { Long userId = rs.getLong("id"); user = UserDB.getUser(con, userId); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return user; }
From source file:com.wso2telco.historylog.DbTracelog.java
/** * Log history./*from w w w . j a va2 s . co m*/ * * @param Reqtype the reqtype * @param isauthenticated the isauthenticated * @param application the application * @param authUser the auth user * @param authenticators the authenticators * @param ipaddress the ipaddress * @throws LogHistoryException the log history exception */ public static void LogHistory(String Reqtype, boolean isauthenticated, String application, String authUser, String authenticators, String ipaddress) throws LogHistoryException { Connection con = null; PreparedStatement pst = null; try { con = DbTracelog.getMobileDBConnection(); String sql = "INSERT INTO sp_login_history (reqtype, application_id, authenticated_user, isauthenticated," + " authenticators,ipaddress, created, created_date)" + " VALUES " + "(?, ?, ?, ?, ?, ?, ?, ?)"; pst = con.prepareStatement(sql); pst.setString(1, Reqtype); pst.setString(2, application); pst.setString(3, authUser); pst.setInt(4, (isauthenticated ? 1 : 0)); pst.setString(5, authenticators); pst.setString(6, ipaddress); pst.setString(7, "authUser"); pst.setTimestamp(8, new java.sql.Timestamp(new java.util.Date().getTime())); pst.executeUpdate(); } catch (SQLException e) { handleException( "Error occured while Login SP LogHistory: " + application + " Service Provider: " + authUser, e); } finally { DbUtil.closeAllConnections(pst, con, null); } }
From source file:com.sql.SECExceptions.java
/** * Inserts an exception to the database/*from w ww. j ava 2 s.c o m*/ * * @param item SECExceptionsModel * @return boolean */ public static boolean insertException(SECExceptionsModel item) { Connection conn = null; PreparedStatement ps = null; try { conn = DBConnection.connectToDB(); String sql = "INSERT INTO SECExceptions (" + "className, " + "methodName, " + "exceptionType, " + "exceptionDescrption, " + "timeOccurred " + ") VALUES (" + "?, " + "?, " + "?, " + "?, " + "GETDATE())"; ps = conn.prepareStatement(sql); ps.setString(1, item.getClassName()); ps.setString(2, item.getMethodName()); ps.setString(3, item.getExceptionType()); ps.setString(4, item.getExceptionDescription()); ps.executeUpdate(); } catch (SQLException ex) { System.out.println(ex.toString()); return true; } finally { DbUtils.closeQuietly(ps); DbUtils.closeQuietly(conn); } return false; }
From source file:ca.qc.adinfo.rouge.leaderboard.db.LeaderboardDb.java
public static Leaderboard getLeaderboard(DBManager dbManager, String key) { Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null;//from www .ja v a 2 s . c o m String sql = "SELECT score, user_id FROM rouge_leaderboard_score " + "WHERE `leaderboard_key` = ? ORDER BY `score` DESC LIMIT 5;"; try { connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); stmt.setString(1, key); Leaderboard leaderboard = new Leaderboard(key); rs = stmt.executeQuery(); while (rs.next()) { Score score = new Score(rs.getLong("user_id"), rs.getLong("score")); leaderboard.addScore(score); } return leaderboard; } 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.dynamobi.network.DynamoNetworkUdr.java
/** * Procedure to avoid an explicit insert yourself. *//*from w w w .j av a 2 s . co m*/ public static void addRepo(String repoUrl) throws SQLException { Connection conn = DriverManager.getConnection("jdbc:default:connection"); String query = "INSERT INTO localdb.sys_network.repositories (repo_url) " + "VALUES (?)"; PreparedStatement ps = conn.prepareStatement(query); ps.setString(1, repoUrl); ps.execute(); ps.close(); }
From source file:com.dynamobi.network.DynamoNetworkUdr.java
/** * Does the delete for you./*from w w w . j a v a 2 s . co m*/ */ public static void removeRepo(String repoUrl) throws SQLException { Connection conn = DriverManager.getConnection("jdbc:default:connection"); String query = "DELETE FROM localdb.sys_network.repositories WHERE " + "repo_url = ?"; PreparedStatement ps = conn.prepareStatement(query); ps.setString(1, repoUrl); ps.execute(); ps.close(); }
From source file:com.zimbra.cs.mailbox.util.MetadataDump.java
private static int lookupMailboxIdFromEmail(DbConnection conn, String email) throws SQLException, ServiceException { PreparedStatement stmt = null; ResultSet rs = null;//from w w w . jav a 2 s. c o m try { String sql = "SELECT id FROM mailbox WHERE comment=?"; stmt = conn.prepareStatement(sql); stmt.setString(1, email.toUpperCase()); rs = stmt.executeQuery(); if (!rs.next()) throw ServiceException.INVALID_REQUEST("Account " + email + " not found on this host", null); return rs.getInt(1); } finally { DbPool.closeResults(rs); DbPool.closeStatement(stmt); } }