我开发了一款安卓应用。
该应用程序执行从 android 插入 mysql 数据库的值。
在这里,我调用了 Soap Web 服务。
在这里,我如何验证我的 edittext 字段。
这是我的网络服务代码:
public class RetailerWs {
public String insertData(String Firstname,String Lastname){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xcart-432pro","root","");
PreparedStatement statement = con.prepareStatement("INSERT INTO xcart_customers(firstname,lastname) VALUES ('"+Firstname+"','"+Lastname+"');");
int result = statement.executeUpdate();
}
catch(Exception exc){
System.out.println(exc.getMessage());
}
return "Registration is successfull!!";
}
}
这是我的安卓代码:
btninsert = (Button)findViewById(R.id.btn_login);
btninsert.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
insertValues();
}
});
}
public void insertValues(){
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
EditText Firstname = (EditText) findViewById(R.id.tf_userName);
String user_Name = Firstname.getText().toString();
EditText Lastname = (EditText) findViewById(R.id.tf_password);
String user_Password = Lastname.getText().toString();
PropertyInfo unameProp =new PropertyInfo();
unameProp.setName("Firstname");//Define the variable name in the web service method
unameProp.setValue(user_Name);//Define value for fname variable
unameProp.setType(String.class);//Define the type of the variable
request.addProperty(unameProp);//Pass properties to the variable
//Pass value for userPassword variable of the web service
PropertyInfo passwordProp =new PropertyInfo();
passwordProp.setName("Lastname");
passwordProp.setValue(user_Password);
passwordProp.setType(String.class);
request.addProperty(passwordProp);
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.result);
result.setText(response.toString());
}
catch(Exception e){
}
我如何验证edittext字段。请帮助我