下拉值通过android中的soap webservices保存在mysql数据库中
Posted
技术标签:
【中文标题】下拉值通过android中的soap webservices保存在mysql数据库中【英文标题】:dropdown value is save in mysql database via soap webservices in android 【发布时间】:2012-08-22 11:25:21 【问题描述】:我希望通过android中的soap webservice在mysql数据库中插入下拉值...如果我必须从我的android应用程序中更改下拉值意味着更新值也保存在mysql数据库中...该怎么做。请帮帮我。
这是我的网络服务代码:
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
);
如果我必须在单击插入按钮后从微调器中选择值意味着它没有被插入。应用程序被强制关闭...请检查我的代码并为我提供正确的解决方案。
【问题讨论】:
【参考方案1】:为这个插入函数使用下面的代码:
String selectedItem = parent.getItemAtPosition(pos).toString();
【讨论】:
以上是关于下拉值通过android中的soap webservices保存在mysql数据库中的主要内容,如果未能解决你的问题,请参考以下文章