1 package com.Yasna.forum.Tasks; 2 3 import com.Yasna.forum.database.SystemProperty; 4 import com.Yasna.forum.database.DbConnectionManager; 5 6 import java.sql.Connection ; 7 import java.sql.PreparedStatement ; 8 import java.sql.SQLException ; 9 import java.sql.ResultSet ; 10 11 63 64 67 public class CleanAccounts { 68 private static final String GET_NOTACTIVE= "select distinct userID from yazdUserProp where name=?"; 69 private static final String DELETE_PERMISSIONS = 70 "DELETE FROM yazdUserPerm WHERE userID=?"; 71 private static final String DELETE_PROPERTIES = 72 "DELETE FROM yazdUserProp WHERE userID=?"; 73 private static final String DELETE_GROUPS= 74 "delete from yazdGroupUser where userID=?"; 75 private static final String DELETE_USER= 76 "delete from "+ SystemProperty.getProperty("User.Table")+" where "+SystemProperty.getProperty("User.Column.UserID")+"=?"; 77 public CleanAccounts(){ 78 Connection con = null; 79 PreparedStatement pstmt = null; 80 try { 81 con = DbConnectionManager.getConnection(); 82 pstmt = con.prepareStatement(GET_NOTACTIVE); 83 pstmt.setString(1,"notactive"); 84 ResultSet rs = pstmt.executeQuery(); 85 while(rs.next()){ 86 int userid=rs.getInt("userID"); 87 pstmt = con.prepareStatement(DELETE_PERMISSIONS); 88 pstmt.setInt(1,userid); 89 pstmt.executeUpdate(); 90 pstmt = con.prepareStatement(DELETE_PROPERTIES); 91 pstmt.setInt(1,userid); 92 pstmt.executeUpdate(); 93 pstmt = con.prepareStatement(DELETE_GROUPS); 94 pstmt.setInt(1,userid); 95 pstmt.executeUpdate(); 96 pstmt = con.prepareStatement(DELETE_USER); 97 pstmt.setInt(1,userid); 98 pstmt.executeUpdate(); 99 } 100 } 101 catch( SQLException sqle ) { 102 System.err.println("CleanAccounts (3) Exception:"+sqle.getMessage()); 103 sqle.printStackTrace(); 104 } 105 catch (Exception e) { 106 System.err.println("CleanAccounts (92) Exception:"+e.getMessage()); 107 } 108 finally { 109 try { pstmt.close(); } 110 catch (Exception e) { e.printStackTrace(); } 111 try { con.close(); } 112 catch (Exception e) { e.printStackTrace(); } 113 } 114 115 } 116 117 } 118 | Popular Tags |