List of usage examples for java.sql PreparedStatement setString
void setString(int parameterIndex, String x) throws SQLException;
String
value. From source file:edu.jhu.pha.vospace.oauth.MySQLOAuthProvider2.java
/** * Generate a fresh request token and secret for a consumer. * //w ww. j a v a 2s. c o m * @throws OAuthException */ public static synchronized Token generateAccessToken(final Token requestToken, String verifier) { // generate oauth_token and oauth_secret final String consumer_key = (String) requestToken.getConsumer().getKey(); // generate token and secret based on consumer_key // for now use md5 of name + current time as token final String token_data = consumer_key + System.nanoTime(); final String token = DigestUtils.md5Hex(token_data); // first remove the accessor from cache int numChanged = DbPoolServlet.goSql("Insert new access token", "update oauth_accessors set request_token = NULL, access_token = ?, created = ? where request_token = ? and authorized = 1", new SqlWorker<Integer>() { @Override public Integer go(Connection conn, PreparedStatement stmt) throws SQLException { stmt.setString(1, token); stmt.setString(2, dateFormat.format(Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime())); stmt.setString(3, requestToken.getToken()); return stmt.executeUpdate(); } }); if (numChanged == 0) { return null; } return new Token(token, requestToken.getSecret(), requestToken.getConsumer().getKey(), requestToken.getCallbackUrl(), requestToken.getAttributes()); }
From source file:com.wso2telco.core.mnc.resolver.dao.OperatorDAO.java
public static String getOperatorByMCCMNC(String mcc, String mnc) throws MobileNtException { Connection conn = null;/* w ww. j a va2 s. c o m*/ PreparedStatement ps = null; ResultSet rs = null; String operator = null; try { String sql = "SELECT operatorname FROM operators WHERE mcc = ? AND mnc = ?"; conn = getDBConnection(); ps = conn.prepareStatement(sql); ps.setString(1, mcc); ps.setString(2, mnc); rs = ps.executeQuery(); while (rs.next()) { operator = rs.getString("operatorname"); log.debug("operator in getOperatorByMCCMNC: " + operator); } } catch (SQLException e) { log.error("database operation error in getOperatorByMCCMNC : ", e); handleException("Error occured while getting operator for mcc : " + mcc + " and mnc : " + mnc + "from the database", e); } catch (Exception e) { log.error("error in getOperatorByMCCMNC : ", e); handleException("Error occured while getting operator for mcc : " + mcc + " and mnc : " + mnc + "from the database", e); } finally { DbUtils.closeAllConnections(ps, conn, rs); } return operator; }
From source file:com.freemedforms.openreact.db.DbSchema.java
/** * Record record of patch into tPatch table so that patches only run once. * /*from w w w . j a v a2 s . co m*/ * @param patchName * @return Success. */ public static boolean recordPatch(String patchName) { Connection c = Configuration.getConnection(); boolean status = false; PreparedStatement cStmt = null; try { cStmt = c.prepareStatement( "INSERT INTO tPatch " + " ( patchName, stamp ) " + " VALUES ( ?, NOW() ) " + ";"); cStmt.setString(1, patchName); cStmt.execute(); status = true; } catch (NullPointerException npe) { log.error("Caught NullPointerException", npe); } catch (SQLException sq) { log.error("Caught SQLException", sq); } catch (Throwable e) { } finally { DbUtil.closeSafely(cStmt); DbUtil.closeSafely(c); } return status; }
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 av a 2 s . c o 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:org.red5.webapps.admin.controllers.service.UserDAO.java
public static boolean addUser(String username, String hashedPassword) { boolean result = false; Connection conn = null;/*from www . j ava2 s .c o m*/ PreparedStatement stmt = null; try { conn = UserDatabase.getConnection(); //make a statement stmt = conn .prepareStatement("INSERT INTO APPUSER (username, password, enabled) VALUES (?, ?, 'enabled')"); stmt.setString(1, username); stmt.setString(2, hashedPassword); log.debug("Add user: {}", stmt.execute()); //add role stmt = conn.prepareStatement("INSERT INTO APPROLE (username, authority) VALUES (?, 'ROLE_SUPERVISOR')"); stmt.setString(1, username); log.debug("Add role: {}", stmt.execute()); // result = true; } catch (Exception e) { log.error("Error connecting to db", e); } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException e) { } } if (conn != null) { UserDatabase.recycle(conn); } } return result; }
From source file:las.DBConnector.java
public static void insertItemIntoTable(Item item) throws SQLException { String data = "INSERT INTO Items(title, author, type, amountleft)" + "Values (?,?,?,?)"; PreparedStatement pt = conn.prepareStatement(data); pt.setString(1, item.getTitle()); pt.setString(2, item.getAuthor());//from w ww. j a va 2 s.c o m pt.setString(3, item.getType()); pt.setInt(4, item.getAmountLeft()); pt.executeUpdate(); }
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 . j av a 2s.c om*/ 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:ch.newscron.referral.ReferralManager.java
/** * Given a customer id and a generated short URL, inserts these two as a new row in the ShortURL table of the database * @param customerId an long representing the unique customer id * @param shortURL a String representing the short goo.gl generated URL */// w w w . jav a 2 s .c o m public static boolean insertShortURL(long customerId, String shortURL) { Connection connection = null; PreparedStatement query = null; try { connection = connect(); query = connection.prepareStatement("INSERT IGNORE INTO ShortURL (custId, shortUrl) VALUES(?, ?)"); query.setLong(1, customerId); query.setString(2, shortURL); int newShortURL = query.executeUpdate(); return newShortURL == 1; } catch (Exception ex) { Logger.getLogger(ReferralManager.class.getName()).log(Level.SEVERE, null, ex); } finally { disconnect(connection, query); } return false; }
From source file:ca.qc.adinfo.rouge.variable.db.PersistentVariableDb.java
public static Variable getPersitentVariable(DBManager dbManager, String key) { Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null;/*w ww. j a v a 2 s . c om*/ String sql = "SELECT value, version FROM rouge_persistant_variable WHERE `key` = ?"; try { connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); stmt.setString(1, key); rs = stmt.executeQuery(); if (rs.next()) { JSONObject jSonObject = JSONObject.fromObject(rs.getString("value")); return new Variable(key, new RougeObject(jSonObject), rs.getLong("version")); } else { return null; } } catch (SQLException e) { log.error(e); return null; } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(connection); } }
From source file:com.wso2telco.util.DbUtil.java
public static String getContextIDForHashKey(String hashKey) throws AuthenticatorException, SQLException { String sessionDataKey = null; String sql = "select contextid from sms_hashkey_contextid_mapping where hashkey=?"; Connection connection = null; PreparedStatement ps = null; ResultSet rs = null;//from w ww . j a va 2 s. co m try { connection = getConnectDBConnection(); ps = connection.prepareStatement(sql); ps.setString(1, hashKey); rs = ps.executeQuery(); while (rs.next()) { sessionDataKey = rs.getString("contextid"); } } catch (SQLException e) { handleException(e.getMessage(), e); } finally { IdentityDatabaseUtil.closeAllConnections(connection, rs, ps); } return sessionDataKey; }