Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. MySqlConnect con=new MySqlConnect();
  2. public PreparedStatement preparedStatement = null;
  3.  
  4. public Connection con1 = con.connect();
  5.  
  6.  
  7.  
  8. //pick up queue and send email
  9. public void email() throws Exception {
  10.  
  11.  
  12. try{
  13.  
  14. while(true) {
  15. String sql = "SELECT id,user,subject,recipient,content FROM emailqueue WHERE status='Pending' ";
  16. PreparedStatement statement = con1.prepareStatement(sql);
  17. ResultSet rs = statement.executeQuery();
  18.  
  19.  
  20.  
  21. while (rs.next()) {
  22.  
  23. String subject = rs.getString("subject");
  24.  
  25. String recipient = rs.getString("recipient");
  26.  
  27. String content = rs.getString("content");
  28.  
  29. String id = rs.getString("id");
  30. String username = rs.getString("user");
  31.  
  32. String emailStatus = "DONE";
  33. String errormsg=sendEmail(recipient, subject, content, id,username);
  34. if (!errormsg.equals("")) {
  35. emailStatus = "FAILED";
  36.  
  37. }
  38. TerminalLogger.printMsg("Status : " + emailStatus);
  39.  
  40. }
  41. statement.close();
  42. rs.close();
  43.  
  44. }
  45. }
  46.  
  47. }catch(Exception e){
  48.  
  49. e.printStackTrace();
  50. TerminalLogger.printMsg("Exception: "+e.toString());
  51.  
  52. }
  53.  
  54. con1.close();
  55. Thread.sleep(2000);
  56.  
  57. }
  58.  
  59. public Object getrecords() {
  60. try {
  61.  
  62. String sql = "select p.id,p.user,p.subject,p.recipient,p.content from Emailqueue p where " +
  63. "status='Pending'";
  64.  
  65. List<Object[]> resList =(List<Object[]>) em.createQuery(sql).getResultList();
  66. if (resList == null) {
  67. throw new Exception("Error with selection query.");
  68. }
  69.  
  70. if (resList.size() > 0) {
  71. return resList;
  72. }
  73.  
  74. // msg = "Setting <" + name + "> not found.";
  75.  
  76. return null;
  77. } catch (Exception e) {
  78.  
  79. msg = CoreUtil.wrapMsg(CoreUtil.FUNC_ERROR,
  80. this.getClass().getName(), "get(" + "Pending" + ")", e.getMessage());
  81.  
  82.  
  83. return null;
  84. }
  85. }
  86.  
  87. Object records = ejbCon.getSettingsFacade().getrecords();
  88.  
  89. id user subject content recipient status
  90. 1 user1 test example abc@example.com Pending
  91. 2 user2 test2 example cde@example.com Pending
  92.  
  93. String sql = "select NEW
  94. Emailqueue(p.id,p.user,p.subject,p.recipient,p.content) from Emailqueue p
  95. where " +
  96. "p.status='Pending'";
  97. List<Emailqueue> resList =(List<Emailqueue>)
  98. em.createQuery(sql).getResultList();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement