Senden von Daten von java nach php-Datei

Möchte ich in diesem post Daten in Datenbank Via php-Datei. Jetzt, Benutzername,Unternehmen , Aktien und Datum sind veröffentlicht in der Datenbank. Ich will post "Edward", "AHCL", "10" und "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();
     }
Schreibe einen Kommentar