List of usage examples for java.sql Connection prepareStatement
PreparedStatement prepareStatement(String sql) throws SQLException;
PreparedStatement
object for sending parameterized SQL statements to the database. 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 ww. ja va2s. co m 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: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;/*w ww. j a v a 2 s . co 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:com.silverpeas.notation.model.RatingDAO.java
public static long deleteRatings(Connection con, ContributionRatingPK pk) throws SQLException { PreparedStatement prepStmt = con.prepareStatement(QUERY_DELETE_RATING); try {//from w w w . j a v a 2 s . co m prepStmt.setString(1, pk.getInstanceId()); prepStmt.setString(2, pk.getContributionId()); prepStmt.setString(3, pk.getContributionType()); return prepStmt.executeUpdate(); } finally { DBUtil.close(prepStmt); } }
From source file:com.sql.SystemErrorEmailList.java
/** * Gathers a list of active email addresses to send to for the email * for the daily crash report email./* w w w.jav a 2 s . c om*/ * * @return */ public static List<String> getActiveEmailAddresses() { List<String> list = new ArrayList(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT EmailAddress " + "FROM SystemErrorEmailList " + "WHERE active = 1"; ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { if (rs.getString("EmailAddress") != null) { list.add(rs.getString("EmailAddress")); } } } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return list; }
From source file:com.silverpeas.notation.model.RatingDAO.java
public static long deleteComponentRatings(Connection con, String componentInstanceId) throws SQLException { PreparedStatement prepStmt = con.prepareStatement(QUERY_DELETE_COMPONENT_RATINGS); try {/*from ww w . jav a2 s . c o m*/ prepStmt.setString(1, componentInstanceId); return prepStmt.executeUpdate(); } finally { DBUtil.close(prepStmt); } }
From source file:com.sql.SystemEmail.java
/** * Gathers active email accounts for sending or receiving. * //from w w w . j a v a 2 s . c om * @return */ public static boolean loadEmailConnectionInformation() { List<SystemEmailModel> systemEmailList = new ArrayList(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT * FROM SystemEmail WHERE active = 1"; ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { SystemEmailModel row = new SystemEmailModel(); row.setId(rs.getInt("id")); row.setActive(rs.getInt("active")); row.setSection(rs.getString("section")); row.setEmailAddress(rs.getString("emailAddress")); row.setUsername(rs.getString("username")); row.setPassword(rs.getString("password")); row.setIncomingURL(rs.getString("incomingURL")); row.setIncomingPort(rs.getInt("incomingPort")); row.setIncomingProtocol(rs.getString("incomingProtocol")); row.setIncomingFolder(rs.getString("incomingFolder")); row.setOutgoingURL(rs.getString("outgoingURL")); row.setOutgoingPort(rs.getInt("outgoingPort")); row.setOutgoingProtocol(rs.getString("outgoingProtocol")); row.setOutgoingFolder(rs.getString("outgoingFolder")); systemEmailList.add(row); } Global.setSystemEmailParams(systemEmailList); } catch (SQLException ex) { ExceptionHandler.Handle(ex); return false; } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return true; }
From source file:com.l2jfree.gameserver.instancemanager.RaidPointsManager.java
public static void cleanUp() { Connection con = null; try {//from ww w .j a va 2 s . c om con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement; statement = con.prepareStatement("DELETE from character_raid_points WHERE charId > 0"); statement.executeUpdate(); statement.close(); _list.clear(); } catch (Exception e) { _log.fatal("could not clean raid points: ", e); } finally { L2DatabaseFactory.close(con); } }
From source file:org.red5.webapps.admin.controllers.service.UserDAO.java
public static AdminUserDetails getUser(String username) { AdminUserDetails details = null;/* w w w . j a va 2s.c o 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.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 {/*from w w w .j a v a 2 s. c om*/ 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: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 www . j ava2s. co m*/ */ 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); } }