我试图通过soap调用从mysql数据库中检索数据。
这里面临以下问题。
我使用了以下网络服务代码:
public class RetailerWs {
public String customerData1(){
String customerInfo = "";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xcart-432pro","root","");
//Find customer information where the customer ID is maximum
PreparedStatement statement = con.prepareStatement("SELECT * FROM xcart_orders");
ResultSet result = statement.executeQuery();
while(result.next()){
customerInfo = customerInfo
+ result.getString("orderid")
+ " " // this to separate order id from status
+ result.getString("status")
+ " "
+ result.getString("payment_method")
+ " "
+ result.getString("total")
+ " "
// this to separate order id from status
+ result.getString("login")
+ "&" ;
}}
catch(Exception exc){
System.out.println(exc.getMessage());
}
return customerInfo;
}}
这是我的安卓代码:
public class RetailerActivity extends Activity {
ListView list;
private static final String SOAP_ACTION = "http://xcart.com/customerData1";
private static final String METHOD_NAME = "customerData1";
private static final String NAMESPACE = "http://xcart.com";
private static final String URL = "http://192.168.1.168:8089/XcartLogin/services/RetailerWs?wsdl";
private static final String KEY_STATUS = "status";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
try {
ht.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
SoapPrimitive s = response;
String str = s.toString();
String resultArr[] = str.split("&");
list=(ListView)findViewById(R.id.list);
// ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
//R.layout.list_row, R.id.orderid);
list.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1,resultArr));
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String s2= getIntent().getStringExtra("status");
// Starting new intent
Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
in.putExtra(KEY_STATUS, s2);
startActivity(in);
}
});
}
catch (Exception e) {
e.printStackTrace();
}
}
}
这是我目前的 o/p:
但我希望需要如下格式的 o/p:
1 P 399.99
Krishna
Check(manual processing)
------------------------------
2 P 314.65
Krishna
Phone Ordering
------------------------------
请帮助我..我该如何开发这个。