【发布时间】:2015-05-16 18:32:23
【问题描述】:
我想通过 php 文件将此数据发布到数据库中。现在,用户名、公司、股票和日期已发布在数据库中。我想发布“Edward”、“AHCL”、“10”和“23-04-2015”
public void Insert(View view){
String UserName="Edward";
//String Company = company.getText().toString();
// Shares = shares.getText().toString();
// String Date = date.getText().toString();
String Company = "AHCL";
String Shares= "10";
String Date= "23-04-2015";
try {
// open a connection to the site
URL url = new URL("http://10.0.2.2:8080//test/example.php");
URLConnection con = url.openConnection();
// activate the output
con.setDoOutput(true);
PrintStream ps = new PrintStream(con.getOutputStream());
// send your parameters to your site
ps.print("&Username=Username");
ps.print("&Company=Company");
ps.print("&Shares=Shares");
ps.print("&Date=Date");
// we have to get the input stream in order to actually send the request
con.getInputStream();
// close the print stream
ps.close();
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
}
// creating new product in background thread
//new CreatePortfolio().execute();
}
【问题讨论】: