如何使用wamp服务器在数据库中发送Spinner选定的值

时间:2017-12-09 08:15:11

标签: java android database oracle spinner

在这个android代码中,它在数据库中发送描述但不在数据库中发送Spinner值

package com.example.mis_internee.test;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.sql.SQLOutput;
import java.util.HashMap;
import java.util.Map;


public class atd_leave_form extends AppCompatActivity {

    EditText Descr, lastname, age;
    Button insert;
    TextView back;
    RequestQueue requestQueue;
    String insertUrl = "http://192.168.0.102/A/issue.php";
    //    String showUrl = "http://192.168.1.65/tutorial/showStudents.php";
    TextView TV;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_atd_leave_form);

        Descr = (EditText) findViewById(R.id.descText);
        insert = (Button) findViewById(R.id.send);
        TV = (TextView) findViewById(R.id.uname);
        back = (TextView) findViewById(R.id.Back);
//        TV= (TextView)findViewById(R.id.textView);

        final Spinner staticSpinner = (Spinner) findViewById(R.id.spinner);
        ArrayAdapter<CharSequence> staticAdapter = ArrayAdapter.createFromResource(this, R.array.list,android.R.layout.simple_spinner_item);
        staticAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        staticSpinner.setAdapter(staticAdapter);



//         String name= "Username= "+getIntent().getExtras().getString("username");
//        TV.setText(name);


//       String name= "Username= "+getIntent().getExtras().getString("username");
//        result.setText(name);

//
//        back.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent i = new Intent(atd_leave_form.this, MainActivity.class);
//                startActivity(i);
//
//
//            }
//        });






        requestQueue = Volley.newRequestQueue(getApplicationContext());


        insert.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String DESCR = Descr.getText().toString();
                final String Spin = staticSpinner.getSelectedItem().toString();

                StringRequest request = new StringRequest(Request.Method.POST, insertUrl, new Response.Listener<String>() {
                    @Override


                    public void onResponse(String response) {
                        if(Descr.getText().toString().equals("")){
                            Toast.makeText(getApplication(),"Please Enter Detail ",Toast.LENGTH_LONG).show();
                        }
                        else if(Descr.getText().toString().length()<10){
                            Toast.makeText(getApplication(),"Text Must be Greater Than 10",Toast.LENGTH_LONG).show();
                        }
                        else{
                            System.out.println(response.toString());
                            Toast.makeText(getApplication(),"Application Submitted Successfully....!",Toast.LENGTH_LONG).show();
                            Intent intent = new Intent(atd_leave_form. this, Issue.class);
                            startActivity(intent);

                        }
                    }}, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {

                    }
                }) {

                    @Override
                    protected Map<String, String> getParams() throws AuthFailureError {
                        Map<String,String> parameters  = new HashMap<String, String>();
                        parameters.put("Descr",Descr.getText().toString());
                        parameters.put("Spin",staticSpinner.toString());
                        return parameters;
                    }
                };
                requestQueue.add(request);
            }

        });


    }

}

我使用了微调器并选择了值并提交了它,但数据库中的提交描述没有错误。我正在使用带有wamp服务器的oracle Web服务,但提交微调器值的描述不是。 提前谢谢

1 个答案:

答案 0 :(得分:1)

在发布参数时使用staticSpinner.getSelectedItem().toString()代替staticSpinner.toString() 您在代码下面发布了错误的数据检查

     insert.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String DESCR = Descr.getText().toString();
                final String Spin = staticSpinner.getSelectedItem().toString();

                StringRequest request = new StringRequest(Request.Method.POST, insertUrl, new Response.Listener<String>() {
                    @Override


                    public void onResponse(String response) {
                        if(Descr.getText().toString().equals("")){
                            Toast.makeText(getApplication(),"Please Enter Detail ",Toast.LENGTH_LONG).show();
                        }
                        else if(Descr.getText().toString().length()<10){
                            Toast.makeText(getApplication(),"Text Must be Greater Than 10",Toast.LENGTH_LONG).show();
                        }
                        else{
                            System.out.println(response.toString());
                            Toast.makeText(getApplication(),"Application Submitted Successfully....!",Toast.LENGTH_LONG).show();
                            Intent intent = new Intent(atd_leave_form. this, Issue.class);
                            startActivity(intent);

                        }
                    }}, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {

                    }
                }) {

                    @Override
                    protected Map<String, String> getParams() throws AuthFailureError {
                        Map<String,String> parameters  = new HashMap<String, String>();
                        parameters.put("Descr",Descr.getText().toString());
                        parameters.put("Spin",Spin);//change here
                        return parameters;
                    }
                };
                requestQueue.add(request);
            }

        });


    }

}