我必须开发一个 android 示例。
它执行从 mysql 数据库中获取数据并显示在 android 应用程序上。
我使用了以下网络服务代码:
public class EditProfile {
public String customerData(String Username,String Password,String Firstname,String Lastname,String Company,String Taxnumber,String Baddress,String Bcity,String Bstate,String Bcountry,String Bzipcode,String Saddress,String Scity,String Sstate,String Scountry,String Szipcode,String Email,String Phone,String Fax,String Url){
String customerInfo = "";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://10.0.0.75:3306/xcart432pro","root","");
PreparedStatement statement = con.prepareStatement("SELECT * FROM xcart_customers where login = '"+Username+"'");
ResultSet result = statement.executeQuery();
while(result.next()){
customerInfo = customerInfo + result.getString("login") + ":" +result.getString("password")+ ":" +result.getString("firstname")
}
}
catch(Exception exc){
System.out.println(exc.getMessage());
}
return customerInfo;
}
我使用了以下android代码:
public class RetailerActivity extends Activity {
private final String NAMESPACE = "http://xcart.com";
private final String URL = "http://10.0.0.75:8085/XcartLogin/services/EditProfile?wsdl";
private int i;
private final String SOAP_ACTION = "http://xcart.com/customerData";
private final String METHOD_NAME = "customerData";
String str,mTitle;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
ht.call(SOAP_ACTION, envelope);
SoapPrimitive s = response;
str = s.toString();
String[] words = str.split(":");
TextView tv = (TextView) findViewById(R.id.user);
tv.setText(Username);
EditText tv1 = (EditText) findViewById(R.id.pass);
tv1.setText(words[1].toString());
EditText tv2 = (EditText) findViewById(R.id.tf_userName);
tv2.setText(words[2].toString());
for (int i = 0, l = words.length; i < l; ++i) {
}}
catch (Exception e) {
e.printStackTrace();
}
}}
在这里我必须运行应用程序意味着从 mysql 数据库中获取数据并在 android 上显示数据。但我没有得到响应。我怎样才能得到它。
在这里我必须写出像静态这样的条件:
SELECT * FROM xcart_customers where login = 'mercy'"); means fetching the data from mysql database and display the data for that user.its successfully worked.
但我已经动态编写代码意味着
"SELECT * FROM xcart_customers where login = '"+Username+"'"); means
没有得到回应。请帮助我。
我如何开发这些。给我解决方案或想法。