我正在使用粘贴的教程代码连接到 MySQL 数据库并简单地发布到表中。Android 应用程序从数据字段正确返回文本,我看到通过端口 8080 进入 Apache 的流量。但是,当我通过 3306 嗅探进入数据库接口的流量时,我什么也看不到,并且 Mysql 中的 count(*) 返回 0 个条目。如何查看 JDBC 对数据的处理方式?
Java 网络服务
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;
}
}
Java Web 服务客户端
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){
}
}
}