1. Are you ready for the Galaxy S20? Here is everything we know so far!

insert spinner selected value in mysql database via soap webservices in android

Discussion in 'Android Development' started by krishnaveni, Aug 23, 2012.

  1. krishnaveni

    krishnaveni Well-Known Member
    Thread Starter

    hi i i have to develop the app is insert the database from spinner in mysql database via soap webserices in android application...

    i have use below webservice code:
    Code (Text):
    1. package com.xcart;
    2. import java.sql.Connection;
    3. import java.sql.DriverManager;
    4. import java.sql.PreparedStatement;
    5.  
    6. public class Insertion {
    7.  
    8.  public String insertData(String userName,String userPassword){
    9.    
    10.   try{
    11.    
    12.    Class.forName("com.mysql.jdbc.Driver");
    13.    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/androidlogin","root","");
    14.    PreparedStatement statement =  con.prepareStatement("INSERT INTO user(status) VALUES ('"+userName+"');");
    15.    int result = statement.executeUpdate();
    16.   }
    17.    
    18.    catch(Exception exc){
    19.     System.out.println(exc.getMessage());
    20.     }
    21.  
    22.   return "Insertion successfull!!";
    23.   }
    24.  
    25. }
    this is my android source code for spinner:
    Code (Text):
    1.  
    2. public class InsertionExample extends Activity{
    3.     private final String NAMESPACE = "http://xcart.com";
    4.     private final String URL = "http://192.168.1.168:8085/XcartLogin/services/Insertion?wsdl";
    5.     private final String SOAP_ACTION = "http://xcart.com/insertData";
    6.     private final String METHOD_NAME = "insertData";
    7.     Button btninsert;
    8.     private Spinner spnMusketeers;
    9.     /** Called when the activity is first created. */
    10.     @Override
    11.     public void onCreate(Bundle savedInstanceState) {
    12.         super.onCreate(savedInstanceState);
    13.         setContentView(R.layout.main);
    14.        
    15.    
    16.         btninsert = (Button)findViewById(R.id.btn_insert);  
    17.         btninsert.setOnClickListener(new View.OnClickListener() {
    18.             public void onClick(View v) {
    19.              insertValues();
    20.             }
    21.         });
    22.     }
    23.      
    24.     public void insertValues(){
    25.    
    26.      
    27.         SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    28.         Spinner userName = (Spinner) findViewById(R.id.spnMusketeers);
    29.         List<String> lsMusketeers = new ArrayList<String>();
    30.         lsMusketeers.add("Q");
    31.         lsMusketeers.add("P");
    32.         lsMusketeers.add("C");
    33.  
    34.         ArrayAdapter<String> aspnMusketeers =
    35.           new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
    36.            lsMusketeers);
    37.         aspnMusketeers.setDropDownViewResource
    38.            (android.R.layout.simple_spinner_dropdown_item);
    39.         spnMusketeers.setAdapter(aspnMusketeers);
    40.  
    41.     // Set up a callback for the spinner
    42.     spnMusketeers.setOnItemSelectedListener(
    43.         new OnItemSelectedListener() {
    44.             public void onNothingSelected(AdapterView<?> arg0) { }
    45.  
    46.             public void onItemSelected(AdapterView<?> parent, View v,
    47.              int position, long id)  {
    48.  
    49.               // Code that does something when the Spinner value changes
    50.             }
    51.            
    52.         });
    53.         String user_Name = userName.getContext().toString();
    54.        
    55.          
    56.         //Pass value for userName variable of the web service
    57.            PropertyInfo unameProp =new PropertyInfo();
    58.            unameProp.setName("userName");//Define the variable name in the web service method
    59.            unameProp.setValue(user_Name);//Define value for fname variable
    60.            unameProp.setType(String.class);//Define the type of the variable
    61.            request.addProperty(unameProp);
    62.            
    63.                
    64.              SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    65.              envelope.setOutputSoapObject(request);
    66.              HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    67.            
    68.              try{
    69.               androidHttpTransport.call(SOAP_ACTION, envelope);
    70.                  SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
    71.                  
    72.                  TextView result = (TextView) findViewById(R.id.textView2);
    73.                  result.setText(response.toString());
    74.            
    75.           }
    76.           catch(Exception e){
    77.            
    78.           }
    79.            // Code that does something when the Spinner value changes
    80.          }
    81.    
    82.    
    83.        
    84.        
    85.     }
    86.  
    87.  
    my logcat window says following error:
    please help me....what error is occurred here.give me solution...
     



    1. Download the Forums for Android™ app!


      Download

       
  2. krishnaveni

    krishnaveni Well-Known Member
    Thread Starter

    i got the solution for this...
    use below code for this insert function:
     
Loading...

Share This Page

Loading...