java.sql.SQLException:在 Web 服务中没有为参数 2 指定值



我在尝试向网络服务发出 POST 请求时遇到问题,请查看我的网络服务和 Android 方法中我的方法的结构,但我没有发现错误。

这是我的安卓类,我的方法叫做:

onClickUpdate (final int position, end String identifier(

public class tareasFragmento extends Fragment implements TareasAdapter.OnClickButton{
private String url = "http://192.168.1.128:8080/WebServiceExamenFinal/webapi/tareas";
private ArrayList<Tareas> listatarea = new ArrayList<>();

//Si no funciona esto se puede borrar
AlertDialog alertDialog;
private List<Tareas> tareasList;
private TareasAdapter tareasAdapter;
private int assiId;
public tareasFragmento() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_tareas, container, false);

RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_list);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2,
GridLayoutManager.VERTICAL, false));
final TareasAdapter adapter = new TareasAdapter(getActivity(), listatarea);
adapter.setCallback(this);
recyclerView.setAdapter(adapter);
RequestQueue queue = Volley.newRequestQueue(getContext());
final ProgressDialog dialog = new ProgressDialog(getContext());
dialog.setMessage("Por favor espere...");
dialog.show();
try {
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, url,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
deserializarJSONArray(response);
adapter.notifyDataSetChanged();
if (dialog.isShowing()) dialog.dismiss();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(),
"Error al realizar la peticiónn" + error.getMessage(),
Toast.LENGTH_LONG).show();
if (dialog.isShowing()) dialog.dismiss();
}
});
queue.add(jsonArrayRequest);
}catch (Exception e) {
Toast.makeText(getActivity(),"El error es: "+e,Toast.LENGTH_LONG).show();
}
return view;
}
public void deserializarJSONArray(JSONArray jsonArray) {
for (int i = 0; i < jsonArray.length(); i++) {
try {
JSONObject item = jsonArray.getJSONObject(i);
Tareas tareas = new Tareas();
tareas.setId(item.getString("id"));
tareas.setNombreTarea(item.getString("nombreUsuario"));
tareas.setEstudiante(item.getString("estudiante"));
tareas.setNota(item.getString("nota"));
listatarea.add(tareas);
} catch (JSONException e) {
Toast.makeText(getActivity(), "Error al procesar la respuesta de la petición: " + e,
Toast.LENGTH_LONG).show();
}
}
}
@Override
public void onClickUpdate(final int position, final String identificador) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = this.getLayoutInflater();
View MyView = inflater.inflate(R.layout.dialog_signin_updatedonante, null);
final EditText identidad = (EditText)MyView.findViewById(R.id.identificador_tarea);
final EditText nombre_tarea = (EditText)MyView.findViewById(R.id.nombre_tarea);
final EditText nota = (EditText)MyView.findViewById(R.id.nota_tarea);
final EditText estudiante = (EditText)MyView.findViewById(R.id.estudiante_tarea);
identidad.setEnabled(false);
identidad.setText(identificador);
final JSONObject jsonObject = new JSONObject();
try{
jsonObject.put("nombre_tarea","Ejemplo").put("nota","Ejemplo").put("estudiante", "Ejemplo");
}catch(JSONException e){
e.printStackTrace();
}
final RequestQueue queue = Volley.newRequestQueue(getActivity());
builder.setView(MyView)
.setPositiveButton("Registrar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
if(nombre_tarea.getText().toString().equals("") || nota.getText().toString().equals("") || estudiante.getText().toString().equals("")){
Toast.makeText(getActivity(), "Porfavor llena todos los campos", Toast.LENGTH_LONG ).show();
}else{
String urlPut = "http://192.168.1.128:8080/WebServiceExamenFinal/webapi/tareas/";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.PUT, urlPut + identificador, jsonObject,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Toast.makeText(getActivity(), "Se envió correctamente", Toast.LENGTH_LONG).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Ocurrió un error al enviar la información", Toast.LENGTH_LONG).show();
}
});
queue.add(request);
}

}
})
.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Toast.makeText(getActivity(),"No se actualizo ningun registro", Toast.LENGTH_SHORT).show();
alertDialog.dismiss();
}
});
alertDialog = builder.create();
alertDialog.show();
}
@Override
public void onClickDelete(final int position, final String identificador) {

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = this.getLayoutInflater();
View MyView = inflater.inflate(R.layout.dialog_signin_deletedonante, null);
RecyclerView recyclerView = (RecyclerView)getView().findViewById(R.id.recycler_list);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2,
GridLayoutManager.VERTICAL, false));
final TareasAdapter adapter = new TareasAdapter(getActivity(), listatarea);
adapter.setCallback(this);
recyclerView.setAdapter(adapter);
builder.setView(MyView)
.setPositiveButton("Eliminar", new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, int id) {
//Toast.makeText(getActivity(),"id: "+ identificador, Toast.LENGTH_SHORT).show();
String urlDelete = "http://192.168.1.128:8080/WebServiceExamenFinal/webapi/tareas/";
final RequestQueue queue = Volley.newRequestQueue(getActivity());
StringRequest request = new StringRequest(Request.Method.DELETE, urlDelete + identificador, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//Aqui actualizo mi fragmento para que se vean reflejados los cambios, intete usar un notifysetDataChange pero no me
//funciono
tareasFragmento tareas = new tareasFragmento();
android.support.v4.app.FragmentManager manager = getFragmentManager();
manager.beginTransaction().replace(R.id.qwe, tareas).commit();
Toast.makeText(getActivity(), "La tarea se eliminó correctamente", Toast.LENGTH_LONG).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Ocurrió un error en la petición", Toast.LENGTH_LONG).show();
}
}){
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json;charset=utf-8");
return headers;
}
};
queue.add(request);
}
})
.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Toast.makeText(getActivity(),"No se ha eliminado la tarea", Toast.LENGTH_SHORT).show();
alertDialog.dismiss();
}
});
alertDialog = builder.create();
alertDialog.show();
}
}

这是我在网络服务中的 PUT 方法:

@PUT
@Path("{id}")
public void put(@PathParam("id")Integer id, Tareas tareas){
tareas.setId(id);
try {
DaoTareas.getInstance().actualizar(tareas);
} catch (SQLException ex) {
Logger.getLogger(TareasResource.class.getName()).log(Level.SEVERE, null, ex);
}
}

最后,这是我查询的方法:

@Override
public void actualizar(Tareas entidad) throws SQLException {
String query = "UPDATE tareas SET nombre_tarea=?, nota=?, estudiante=? WHERE id = ?";
if (actualizar == null) {
actualizar = Conexion.getInstance().getCon().prepareStatement(query);
}
actualizar.setString(1, entidad.getNombreUsuario());
actualizar.setInt(3, entidad.getId());
actualizar.executeUpdate();
}

您需要添加所有参数:actualizae.setString(2, etidad.getNota())与"?"字符的数量相同。

相关内容

  • 没有找到相关文章

最新更新