如何爲這樣的圖像製作java代碼?適用於Android應用程序的Java代碼插入數據並將數據上傳到MYSQL
也就是說從Android模擬器。我試圖在每個插槽中輸入發佈數據信息並將信息上傳到MySQL數據庫。
這是到目前爲止的代碼:提前
public class Registration extends Activity {
TextView Taccount,Tpassword,Tfirst,Tlast,Temail,Tlocation,Tdescription;
EditText Eaccount,Epassword,Efirst,Elast,Eemail,Elocation,Edescription;
Button btnCreate;
String page="";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cappuccino);
btnCreate = (Button) findViewById(R.id.btnGen);
Taccount = (TextView) findViewById(R.id.txtAccountID);
Eaccount = (EditText) findViewById(R.id.editAccountID);
Tpassword = (TextView) findViewById(R.id.txtPassword);
Epassword = (EditText) findViewById(R.id.editPassword);
Tfirst = (TextView) findViewById(R.id.txtFirst);
Efirst = (EditText) findViewById(R.id.editFirst);
Tlast = (TextView) findViewById(R.id.txtLast);
Elast = (EditText) findViewById(R.id.editLast);
Temail = (TextView) findViewById(R.id.txtEmail);
Eemail = (EditText) findViewById(R.id.editEmail);
Tlocation = (TextView) findViewById(R.id.txtLocation);
Elocation = (EditText) findViewById(R.id.editLocation);
Tdescription = (TextView) findViewById(R.id.txtDescription);
Edescription = (EditText) findViewById(R.id.editDescription);
btnCreate.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
examineJSONFile();
}
});
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_cappuccino, menu);
return true;
}
void examineJSONFile()
{
try
{
JSONObject object=new JSONObject();
object.put("Account ID", Eaccount.getText());
object.put("Password", Epassword.getText());
object.put("First Name", Efirst.getText());
object.put("Last Name", Elast.getText());
object.put("Email", Eemail.getText());
object.put("Location", Elocation.getText());
object.put("Description", Edescription.getText());
String str=object.toString();
executeHttpPost(str);
Log.i("JsonString :", str);
Toast.makeText(this, "Json Objects are : " + str,Toast.LENGTH_LONG).show();
}
catch (Exception je)
{
}
}
public void executeHttpPost(String string) throws Exception
{
//This method for HttpConnection
try
{
HttpClient client = new DefaultHttpClient();
HttpPost request = new HttpPost("http://localhost:8080/example/database/Cappuccino.sql");
List<NameValuePair> value=new ArrayList<NameValuePair>();
value.add(new BasicNameValuePair("Account ID",string));
UrlEncodedFormEntity entity=new UrlEncodedFormEntity(value);
request.setEntity(entity);
client.execute(request);
System.out.println("after sending :"+request.toString());
}
catch(Exception e) {System.out.println("Exp="+e);
}
}
}
謝謝!
那麼...你到底在問什麼?你有什麼嘗試?你做了什麼研究?什麼不起作用? – 0gravity 2012-08-11 04:50:39
嗨,編輯。爲了獲得有用的幫助,通常最好提供一個特定的問題或一組問題,你已經完成的工作來回答他們,並且描述你的障礙。如果您在開始時遇到困難,請嘗試通讀一些Android開發教程。 http://developer.android.com/training/index.html – Carth 2012-08-11 04:53:20