Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MySqlConnect con=new MySqlConnect();
- public PreparedStatement preparedStatement = null;
- public Connection con1 = con.connect();
- //pick up queue and send email
- public void email() throws Exception {
- try{
- while(true) {
- String sql = "SELECT id,user,subject,recipient,content FROM emailqueue WHERE status='Pending' ";
- PreparedStatement statement = con1.prepareStatement(sql);
- ResultSet rs = statement.executeQuery();
- while (rs.next()) {
- String subject = rs.getString("subject");
- String recipient = rs.getString("recipient");
- String content = rs.getString("content");
- String id = rs.getString("id");
- String username = rs.getString("user");
- String emailStatus = "DONE";
- String errormsg=sendEmail(recipient, subject, content, id,username);
- if (!errormsg.equals("")) {
- emailStatus = "FAILED";
- }
- TerminalLogger.printMsg("Status : " + emailStatus);
- }
- statement.close();
- rs.close();
- }
- }
- }catch(Exception e){
- e.printStackTrace();
- TerminalLogger.printMsg("Exception: "+e.toString());
- }
- con1.close();
- Thread.sleep(2000);
- }
- public Object getrecords() {
- try {
- String sql = "select p.id,p.user,p.subject,p.recipient,p.content from Emailqueue p where " +
- "status='Pending'";
- List<Object[]> resList =(List<Object[]>) em.createQuery(sql).getResultList();
- if (resList == null) {
- throw new Exception("Error with selection query.");
- }
- if (resList.size() > 0) {
- return resList;
- }
- // msg = "Setting <" + name + "> not found.";
- return null;
- } catch (Exception e) {
- msg = CoreUtil.wrapMsg(CoreUtil.FUNC_ERROR,
- this.getClass().getName(), "get(" + "Pending" + ")", e.getMessage());
- return null;
- }
- }
- Object records = ejbCon.getSettingsFacade().getrecords();
- id user subject content recipient status
- 1 user1 test example abc@example.com Pending
- 2 user2 test2 example cde@example.com Pending
- String sql = "select NEW
- Emailqueue(p.id,p.user,p.subject,p.recipient,p.content) from Emailqueue p
- where " +
- "p.status='Pending'";
- List<Emailqueue> resList =(List<Emailqueue>)
- em.createQuery(sql).getResultList();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement