AndroidのSOAP Webサービスを介してmysqlデータベースにドロップダウン値を挿入したい... Androidアプリからドロップダウン値を変更する必要がある場合、更新値もmysqlデータベースに保存されることを意味します...どうすればいいですか.助けてください.
これは私のWebサービスコードです:
public class Insertion {
public String insertData(String userName,String userPassword){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/androidlogin","root","");
PreparedStatement statement = con.prepareStatement("INSERT INTO user(status) VALUES ('"+userName+"');");
int result = statement.executeUpdate();
}
catch(Exception exc){
System.out.println(exc.getMessage());
}
return "Insertion successfull!!";
}
}
これは私のアンドロイドコードです:
public class InsertionExample extends Activity{
private final String NAMESPACE = "http://ws.retailer.com";
private final String URL = "http://192.168.1.168:8085/Retailer/services/GetCurrentDateTime?wsdl";
private final String SOAP_ACTION = "http://ws.retailer.com/insertData";
private final String METHOD_NAME = "insertData";
Button btninsert;
private Spinner spnMusketeers;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btninsert = (Button)findViewById(R.id.btn_insert);
btninsert.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
insertValues();
}
});
}
public void insertValues(){
Spinner userName = (Spinner) findViewById(R.id.spnMusketeers);
String user_Name = userName.getContext().toString();
spnMusketeers = (Spinner) findViewById(R.id.spnMusketeers);
List<String> lsMusketeers = new ArrayList<String>();
lsMusketeers.add("Q");
lsMusketeers.add("C");
lsMusketeers.add("P");
lsMusketeers.add("I");
lsMusketeers.add("F");
ArrayAdapter<String> aspnMusketeers =
new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
lsMusketeers);
aspnMusketeers.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
spnMusketeers.setAdapter(aspnMusketeers);
// Set up a callback for the spinner
spnMusketeers.setOnItemSelectedListener(
new OnItemSelectedListener() {
public void onNothingSelected(AdapterView<?> arg0) { }
public void onItemSelected(AdapterView<?> parent, View v,
int position, long id) {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo unameProp =new PropertyInfo();
unameProp.setName("spnMusketeers");//Define the variable name in the web service method
unameProp.setValue(status);//Define value for fname variable
unameProp.setType(String.class);//Define the type of the variable
request.addProperty(unameProp);//Pass properties to the variable
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
TextView result = (TextView) findViewById(R.id.textView2);
result.setText(response.toString());
}
catch(Exception e){
}
// Code that does something when the Spinner value changes
}
});
}
}
挿入ボタンをクリックした後にスピナーから値を選択する必要がある場合は、挿入されていないことを意味します。アプリは強制的に閉じられます...コードを確認して、正しい解決策を教えてください。