fetch the email from mysql server and display on android textview


  1. krishnaveni

    krishnaveni Well-Known Member

    I have to develop one android application.

    Here i have to fetch the email for belonging user and display that email on android textview.how can i develop these.please give me any idea.

    [HIGH]
    public class Login {
    public String authentication(String username,String password){

    String retrievedUserName = "";
    String retrievedPassword = "";
    String retrievedEmail = "";
    String status = "";
    try{
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xcart-432pro","root","");
    PreparedStatement statement = con.prepareStatement("SELECT * FROM xcart_customers WHERE login = '"+username+"'");
    ResultSet result = statement.executeQuery();
    while(result.next()){
    retrievedUserName = result.getString("login");
    retrievedPassword = result.getString("password");
    retrievedEmail = result.getString("email");
    }
    if(retrievedUserName.equals(username)&&retrievedPassword.equals(password)&&!(retrievedUserName.equals("") && retrievedPassword.equals(""))){
    status = retrievedEmail;
    }

    else {
    status = "Login fail!!!";
    }


    }

    catch(Exception e){
    e.printStackTrace();
    }
    return status;

    }

    }
    [/HIGH]

    Here i have to run these webservice code means if login is success means have displayed email id successfully.if my login is incorrect means have displayed login failed message.so my webservice code is correct.

    If my login is success means have to display email on android textview.otherwise have to display login failed message.

    But here i have faced one problem:

    If i have enter correct login detail means thats time also have displayed login failed message.but i have to need the o/p like if my login sucess means display email otherwise login failed message.

    Whats wrong in my code.please give me solution for these.

    This is my android code:
    HTML:
    1.  
    2. public class CustomerLogin extends Activity {
    3. private static final String SPF_NAME = "vidslogin";
    4. private static final String USERNAME = "login";
    5. private static final String PASSWORD = "password";
    6. private static final String PREFS_NAME = null;
    7.  
    8. CheckBox chkRememberMe;
    9.  
    10. String mGrandTotal,total,mTitle,mTotal,mQty,mCost;
    11. EditText username,userPassword;
    12. private final String NAMESPACE = "http://xcart.com";
    13. private final String URL = "http://10.0.0.75:8085/XcartLogin/services/Login?wsdl";
    14. private final String SOAP_ACTION = "http://xcart.com/authentication";
    15. private final String METHOD_NAME = "authentication";
    16.  
    17.  
    18. /**Called when the activity is first created. */
    19. @Override
    20. public void onCreate(Bundle savedInstanceState) {
    21. super.onCreate(savedInstanceState);
    22. setContentView(R.layout.customer_login);
    23. chkRememberMe = (CheckBox) findViewById(R.id.rempasswordcheckbox);
    24. username = (EditText) findViewById(R.id.tf_userName);
    25. userPassword = (EditText) findViewById(R.id.tf_password);
    26. SharedPreferences loginPreferences = getSharedPreferences(SPF_NAME,
    27. Context.MODE_PRIVATE);
    28. username.setText(loginPreferences.getString(USERNAME, ""));
    29. userPassword.setText(loginPreferences.getString(PASSWORD, ""));
    30.  
    31.  
    32. Button login = (Button) findViewById(R.id.btn_login);
    33. login.setOnClickListener(new View.OnClickListener() {
    34.  
    35. public void onClick(View arg0) {
    36. loginAction();
    37.  
    38. }
    39. });
    40. }
    41. private void loginAction(){
    42.  
    43.     boolean isUserValidated = true;
    44.     boolean isPasswordValidated = true;
    45.  
    46.          SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    47.          EditText username = (EditText) findViewById(R.id.tf_userName);
    48.             String user_Name = username.getText().toString();
    49.             EditText userPassword = (EditText) findViewById(R.id.tf_password);
    50.             String user_Password = userPassword.getText().toString();
    51.  
    52.           //Pass value for userName variable of the web service
    53.             PropertyInfo unameProp =new PropertyInfo();
    54.             unameProp.setName("username");//Define the variable name in the web service method
    55.             unameProp.setValue(user_Name);//set value for userName variable
    56.             unameProp.setType(String.class);//Define the type of the variable
    57.             request.addProperty(unameProp);//Pass properties to the variable
    58.  
    59.           //Pass value for Password variable of the web service
    60.             PropertyInfo passwordProp =new PropertyInfo();
    61.             passwordProp.setName("password");
    62.             passwordProp.setValue(user_Password);
    63.             passwordProp.setType(String.class);
    64.             request.addProperty(passwordProp);
    65.  
    66.             SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    67.             envelope.setOutputSoapObject(request);
    68.             HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    69.             try{
    70.                 androidHttpTransport.call(SOAP_ACTION, envelope);
    71.                 SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
    72.                 String status = response.toString();
    73.                 TextView email = (TextView) findViewById(R.id.tv_status);
    74.                   email.setText(response.toString());
    75.                   if(status.equals("email"))
    76.                    {
    77.                        
    78.                        //   ADD  to save  and  read next time
    79.                            String strUserName = username.getText().toString().trim();
    80.                            String strPassword = userPassword.getText().toString().trim();
    81.                            
    82.                            if (null == strUserName || strUserName.length() == 0)
    83.                                        {
    84.                                //  showToast("Enter Your Name");
    85.                                username.setError( "username is required!" );
    86.     isUserValidated = false;
    87.                            }
    88.    if (null == strPassword || strPassword.length() == 0)
    89.                                        {
    90.                                    //      showToast("Enter Your Password");
    91.     isPasswordValidated = false;
    92.                              userPassword.setError( "password is required!" );
    93.                            }
    94. if(isUserValidated = true && isPasswordValidated == true)
    95.                                       {
    96.  
    97.                               if (chkRememberMe.isChecked())
    98.                                               {
    99.                                   SharedPreferences loginPreferences = getSharedPreferences(SPF_NAME, Context.MODE_PRIVATE);
    100.                                    loginPreferences.edit().putString(USERNAME, strUserName).putString(PASSWORD, strPassword).commit();
    101.                                } else
    102.                                                {
    103.                                    SharedPreferences loginPreferences = getSharedPreferences(SPF_NAME, Context.MODE_PRIVATE);
    104.                                    loginPreferences.edit().clear().commit();
    105.                                                }
    106. }
    107.  
    108.     if(isUserValidated && isPasswordValidated)
    109.    {
    110.        
    111.        Intent intent = new Intent(CustomerLogin.this,PayPalIntegrationActivity.class);
    112.  
    113.    
    114.         intent.putExtra("login",username.getText().toString());
    115.         startActivity(intent);
    116.                      
    117.     }
    118.  }
    119.                    
    120.                            else
    121.                               {
    122.                                
    123.                                LayoutInflater inflater = getLayoutInflater();
    124.                                   View layout = inflater.inflate(R.layout.toast_custom_layout,
    125.                                        (ViewGroup) findViewById(R.id.toast_layout_root));
    126.                               Toast toast = new Toast(getApplicationContext());
    127.                                  toast.setGravity(Gravity.TOP, 0, 30);
    128.                                  toast.setDuration(Toast.LENGTH_LONG);
    129.                                  toast.setView(layout);
    130.                                  toast.show();
    131.  
    132.                               }
    133.                              }
    134. catch(Exception e){
    135.  
    136.                       }
    137.                      }
    138.  
    139.               }
    140.  

    Advertisement
Loading...

Share This Page