1

I have been creating an android app. I designed a signup form . Here when people click the signup button the details are added to the mysql table(contains confirmation code as a field.) and the confirmation code is initially set to NULL and then a servlet is called . This servlet contains the code that generates a 4 digit random number and adds it to the mysql table for the particular entry. Then the servlet calls a method in another class that sends confirmation email to the user with the code.

Now when I run the app and servlet a confirmation code is generated and it is sent to the user vie email. But the problem is the mysql table is not getting updated. Note: The code for updation of mysql table is given above the code that send email. However the same servlet updates the mysql table and sends email on submission of a HTML form.

Don't know how to solve this.. For info I am hosting the application on Amazon Elastic Beanstalk.

This is the Servlet part:

protected void processRequest(HttpServletRequest      request,HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    System.out.println("fdsfsdf");
    mBean = new MailSenderBean();
        Random n=new Random();
        int no=n.nextInt();
        no%=10000;
        if(no<0)
        {
            no=-no;
        }
        String code="0000"+no , name = request.getParameter("name"), email = request.getParameter("email");
        code=code.substring(code.length()-4, code.length());
        try{
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection(AppConfig.dbUrl,AppConfig.dbUname, AppConfig.dbPwd);
            PreparedStatement pst=con.prepareStatement("update signup_users set code=\'"+code+"\' where name=\'"+name+"\'");
            pst.execute();
            mBean.sendMail(name, email, code);
            System.out.println("name="+name+",email="+email+",code="+code);
        }catch(Exception e)
        {
            System.out.println(""+e);
        }
    }

and my client side code in android app is


    DefaultHttpClient httpClient  = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(AppConfig.serverUrl);
    List lst =new ArrayList();
    lst.add(new BasicNameValuePair("name", name));
    lst.add(new BasicNameValuePair("email", email));
    httpPost.setEntity(new UrlEncodedFormEntity(lst));
    HttpResponse httpResponse = httpClient.execute(httpPost);

5
  • Please show the relevant parts of your code... otherwise we're all just guessing. Commented Jan 4, 2016 at 19:34
  • please check this .. I have added the servlet code here. Commented Jan 4, 2016 at 19:40
  • Please, post the client code as well. Since you said that your code works well when a http request is made using a html form, the problem may be on the client side (i.e. the Android app) Anyway, did you check your app server logs? Commented Jan 4, 2016 at 19:50
  • Well, you certainly have some other issues here... for starters, you are not using PreparedStatement correctly. You should be paramatizing your inputs to it, with ? characters...mkyong.com/jdbc/… Commented Jan 4, 2016 at 20:21
  • I have added the client side code also.. Check that too.. Commented Jan 4, 2016 at 20:33

1 Answer 1

1

Got the answer from a friend. I was using the wrong field to update in android app but I used the appropriate key in html form. That is why I got wrong output from android app alone..!!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.