貼り付けたチュートリアルコードを使用してMySQLデータベースに接続し、テーブルに投稿するだけです。Androidアプリはデータフィールドからテキストを正しく返しています。ポート8080を介してApacheへのトラフィックが表示されています。ただし、3306を介してデータベースインターフェイスに入るトラフィックをスニッフィングすると、何も表示されず、Mysqlのcount(*)は0エントリを返します。JDBCがデータをどのように処理しているかを確認するにはどうすればよいですか?
JavaWebサービス
package com.retailer.ws;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
public class RetailerWS {
public String customerData(){
String customerInfo = "";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306 /login","root","password");
//Find customer information where the customer ID is maximum
PreparedStatement statement = con.prepareStatement("INSERT INTO users(name,password) VALUES('"+userName+"','"+userPassword"')");
ResultSet result = statement.executeQuery();
while(result.next()){
customerInfo = customerInfo + result.getString("name") + "&" + result.getString("C_ID") + "&"+result.getString("address") + "&"+result.getString("email");
}
}
catch(Exception exc){
System.out.println(exc.getMessage());
}
return customerInfo;
}
}
JavaWebサービスクライアント
package com.userdata.ws;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class AndroidMySQLClientActivity extends Activity{
private final String NAMESPACE = "http://ws.chathura.com";
private final String URL = "http://host:8080/First/services/Users?wsdl";
private final String SOAP_ACTION = "http://ws.chathura.com/insertData";
private final String METHOD_NAME = "insertData";
Button btninsert;
/** 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(){
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
EditText userName = (EditText) findViewById(R.id.editText1);
String user_Name = userName.getText().toString();
EditText userPassword = (EditText) findViewById(R.id.editText2);
String user_Password = userPassword.getText().toString();
//Pass value for userName variable of the web service
PropertyInfo unameProp =new PropertyInfo();
unameProp.setName("userName");//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("userPassword");
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.textView2);
result.setText(response.toString());
}
catch(Exception e){
}
}
}