List of usage examples for java.sql PreparedStatement setString
void setString(int parameterIndex, String x) throws SQLException;
String
value. From source file:com.keybox.manage.db.ProfileDB.java
/** * updates profile/*from www . ja va 2s. co m*/ * * @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:Main.java
public static PreparedStatement createLayersInsertForContextual(Connection conn, int layerId, String description, String path, String name, String displayPath, double minLatitude, double minLongitude, double maxLatitude, double maxLongitude, String path_orig) throws SQLException { PreparedStatement stLayersInsert = conn.prepareStatement( "INSERT INTO layers (id, name, description, type, path, displayPath, minlatitude, minlongitude, maxlatitude, maxlongitude, enabled, displayname, uid, path_orig) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); stLayersInsert.setInt(1, layerId);/*from ww w. java 2 s . c o m*/ stLayersInsert.setString(2, name); stLayersInsert.setString(3, description); stLayersInsert.setString(4, CONTEXTUAL_LAYER_TYPE); stLayersInsert.setString(5, path); stLayersInsert.setString(6, displayPath); stLayersInsert.setDouble(7, minLatitude); stLayersInsert.setDouble(8, minLongitude); stLayersInsert.setDouble(9, maxLatitude); stLayersInsert.setDouble(10, maxLongitude); stLayersInsert.setBoolean(11, true); stLayersInsert.setString(12, description); stLayersInsert.setString(13, Integer.toString(layerId)); stLayersInsert.setString(14, path_orig); return stLayersInsert; }
From source file:com.silverpeas.notation.model.RatingDAO.java
public static void updateRaterRating(Connection con, RaterRatingPK pk, int note) throws SQLException { PreparedStatement prepStmt = con.prepareStatement(QUERY_UPDATE_RATER_RATING); try {// w w w . j a va2 s .com prepStmt.setInt(1, note); prepStmt.setString(2, pk.getInstanceId()); prepStmt.setString(3, pk.getContributionId()); prepStmt.setString(4, pk.getContributionType()); prepStmt.setString(5, pk.getRater().getId()); prepStmt.executeUpdate(); } finally { DBUtil.close(prepStmt); } }
From source file:ch.newscron.registration.UserRegistration.java
public static long getShortUrlId(String shortURL) { Connection connection = null; PreparedStatement query = null; ResultSet rs = null;/*from w w w. ja va 2s. c om*/ try { connection = connect(); query = connection.prepareStatement("SELECT id FROM ShortURL WHERE shortUrl=?"); query.setString(1, shortURL); rs = query.executeQuery(); rs.next(); long shortURLId = rs.getLong("id"); return shortURLId; } catch (Exception ex) { Logger.getLogger(UserRegistration.class.getName()).log(Level.SEVERE, null, ex); } finally { disconnect(connection, query, rs); } return -1; }
From source file:org.red5.webapps.admin.controllers.service.UserDAO.java
public static AdminUserDetails getUser(String username) { AdminUserDetails details = null;//w ww . j a v a 2s .co m Connection conn = null; PreparedStatement stmt = null; try { conn = UserDatabase.getConnection(); //make a statement stmt = conn.prepareStatement("SELECT * FROM APPUSER WHERE username = ?"); stmt.setString(1, username); ResultSet rs = stmt.executeQuery(); if (rs.next()) { log.debug("User found"); details = new AdminUserDetails(); details.setEnabled("enabled".equals(rs.getString("enabled"))); details.setPassword(rs.getString("password")); details.setUserid(rs.getInt("userid")); details.setUsername(rs.getString("username")); // rs.close(); //get role stmt = conn.prepareStatement("SELECT authority FROM APPROLE WHERE username = ?"); stmt.setString(1, username); rs = stmt.executeQuery(); if (rs.next()) { GrantedAuthority[] authorities = new GrantedAuthority[1]; authorities[0] = new GrantedAuthorityImpl(rs.getString("authority")); details.setAuthorities(authorities); // //if (daoAuthenticationProvider != null) { //User usr = new User(username, details.getPassword(), true, true, true, true, authorities); //daoAuthenticationProvider.getUserCache().putUserInCache(usr); //} } } rs.close(); } 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 details; }
From source file:com.freemedforms.openreact.db.DbSchema.java
/** * Determine if a patch has been applied yet. * // ww w . j ava 2s . com * @param patchName * @return Success. */ public static boolean isPatchApplied(String patchName) { Connection c = Configuration.getConnection(); int found = 0; PreparedStatement cStmt = null; try { cStmt = c.prepareStatement("SELECT COUNT(*) FROM tPatch " + " WHERE patchName = ? " + ";"); cStmt.setString(1, patchName); boolean hadResults = cStmt.execute(); if (hadResults) { ResultSet rs = cStmt.getResultSet(); rs.next(); found = rs.getInt(1); rs.close(); } } catch (NullPointerException npe) { log.error("Caught NullPointerException", npe); } catch (Throwable e) { } finally { DbUtil.closeSafely(cStmt); DbUtil.closeSafely(c); } return (boolean) (found > 0); }
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()); 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.silverpeas.notation.model.RatingDAO.java
public static void createRaterRating(Connection con, RaterRatingPK pk, int note) throws SQLException { int newId = 0; try {//from w ww . j av a 2 s . c o m newId = DBUtil.getNextId(TABLE_NAME, COLUMN_ID); } catch (Exception e) { SilverTrace.warn("notation", "RatingDAO.createRaterRating", "root.EX_PK_GENERATION_FAILED", e); } PreparedStatement prepStmt = con.prepareStatement(QUERY_CREATE_RATER_RATING); try { prepStmt.setInt(1, newId); prepStmt.setString(2, pk.getInstanceId()); prepStmt.setString(3, pk.getContributionId()); prepStmt.setString(4, pk.getContributionType()); prepStmt.setString(5, pk.getRater().getId()); prepStmt.setInt(6, note); prepStmt.executeUpdate(); } finally { DBUtil.close(prepStmt); } }
From source file:com.chaosinmotion.securechat.server.commands.Login.java
/** * Process the login request. This returns null if the user could not * be logged in./*from ww w. ja va2s . c o m*/ * * The expected parameters are 'username' and 'password', which should * be hashed. * * @param requestParams * @return * @throws IOException * @throws SQLException * @throws ClassNotFoundException */ public static UserInfo processRequest(JSONObject requestParams, String token) throws ClassNotFoundException, SQLException, IOException { String username = requestParams.optString("username"); String password = requestParams.optString("password"); /* * Obtain user information from database */ Connection c = null; PreparedStatement ps = null; ResultSet rs = null; try { c = Database.get(); ps = c.prepareStatement("SELECT userid, password " + "FROM Users " + "WHERE username = ?"); ps.setString(1, username); rs = ps.executeQuery(); if (rs.next()) { /* * If the result is found, hash the entry in the way it would * be hashed by the front end, and compare to see if the * hash codes match. (This requires that the hashed password * stored in the back-end has a consistent capitalization. * We arbitrarily pick lower-case for our SHA-256 hex string. */ int userID = rs.getInt(1); String spassword = rs.getString(2); /* * Encrypt password with token and salt */ spassword = spassword + Constants.SALT + token; spassword = Hash.sha256(spassword); /* * Compare; if matches, then return the user info record * so we can store away. While the SHA256 process returns * consistent case, we compare ignoring case anyway, just * because. :-) */ if (spassword.equalsIgnoreCase(password)) { return new UserInfo(userID); } } return null; } finally { if (rs != null) rs.close(); if (ps != null) ps.close(); if (c != null) c.close(); } }
From source file:com.sql.EMail.java
/** * Marks an email ready to file by the system. This is in place so a user * does not try to docket an email that is currently being processed. * * @param eml/*from w ww.j a v a 2 s. com*/ */ public static void setEmailReadyToFile(EmailMessageModel eml) { Connection conn = null; PreparedStatement ps = null; try { conn = DBConnection.connectToDB(); String sql = "UPDATE EMail SET readyToFile = ?, emailBodyFileName = ? WHERE id = ?"; ps = conn.prepareStatement(sql); ps.setInt(1, eml.getReadyToFile()); ps.setString(2, eml.getEmailBodyFileName()); ps.setInt(3, eml.getId()); ps.executeUpdate(); } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(ps); DbUtils.closeQuietly(conn); } }