Mblack47 Mblack47 - 1 year ago 68
Android Question

Problemto Create a Class SQL Query Studio Android

My Problem today is that been developing an APP having a Login, A Maintenance Products (For more say), all with the database engine SQL

and create the login all Ok, the procedimeinto a normal login with user and pass ago, also believes maintaining create products, which I take as parameters the name of the product and its respective description, I add, edit, and delete, just not makes the management of search data and show me when access to the corresponding layout, using the onCreate method of my MainMenu but hey that's not the case, the relevant case is that I want to know how to do that through a button, find me the names input on a EditText or are related to the name, and tried to do this using the following code:

package com.sqldata.gst.appsql;

import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

* Created by Administrador on 05/10/2016.

public class ConClientes extends MainActivity {
Conexion conexionSQL;
EditText txtCdCliente, txtNomCli;
Button btnBuscar, btnRetornar;
ProgressBar pgrCliente;
ListView lstClientes;
String idCliente;
//ResultSet rs;

protected void onCreate(Bundle savedInstanceState){

conexionSQL = new Conexion();
txtCdCliente = (EditText) findViewById(R.id.txtCdCliente);
//txtNomCli = (EditText) findViewById(R.id.txtNomCli);
btnBuscar = (Button) findViewById(R.id.btnBuscar);
btnRetornar = (Button) findViewById(R.id.btnRetornar);
pgrCliente = (ProgressBar) findViewById(R.id.pgrCliente);
lstClientes = (ListView) findViewById(R.id.lstClientes);
idCliente = "";

// Evento Ejecutar Boton
btnBuscar.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
SelectClientes selectClientes = new SelectClientes();
selectClientes.execute(""); //Cannot resolve method 'execute(java.lang.String)

public class FillList extends AsyncTask<String, String, String>
String result = "";

List<Map<String, String>> CliList = new ArrayList<Map<String, String>>();

protected void onPreExecute(){

protected void onPostExecute(String r){
Toast.makeText(ConClientes.this, r, Toast.LENGTH_SHORT).show();

String[] from = {"A", "B", "C"};
int[] views = {R.id.lblClienteId, R.id.lblNomCli, R.id.lblCodCli};
final SimpleAdapter ADA = new SimpleAdapter(ConClientes.this, CliList, R.layout.lst_cliente,
from, views);

lstClientes.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
HashMap<String, Object> obj = (HashMap<String, Object>) ADA.getItem(arg2);
idCliente = (String) obj.get("A");
//String ClienName = (String) obj.get("B");
String ClienCod = (String) obj.get("C");


protected String doInBackground (String... params){
Connection cnSQL = conexionSQL.CONN();
if (cnSQL == null){
result = "Error en la Conexión SQL Server";
String query = "select * from clientes";
PreparedStatement psSQL = cnSQL.prepareStatement(query);
ResultSet rsSQL = psSQL.executeQuery();

ArrayList data1 = new ArrayList();
while (rsSQL.next()){
Map<String, String> dataRec = new HashMap<String, String>();
dataRec.put("A", rsSQL.getString("idcliente"));
dataRec.put("B", rsSQL.getString("nom_cli"));
dataRec.put("C", rsSQL.getString("cod_cli"));
result = "Success";
} catch (Exception ex){
result = "Error al Buscar Datos de la Tabla Clientes";
return result;

public class SelectClientes extends ArrayList<String>{

String result = "";
Boolean isSuccess = false;

String ClienCod = txtCdCliente.getText().toString();
String NomCli = txtNomCli.getText().toString();

@Override //Method does not override method from its superclass
protected void onPreExecute(){

protected void onPostExecute(String r){
Toast.makeText(ConClientes.this, r, Toast.LENGTH_SHORT).show();
if (isSuccess == true){
FillList fillList = new FillList();

@Override //Method does not override method from its superclass
protected String doInBackground(String... params){
if (ClienCod.trim().equals(""))
result = "Favor de Introducir el Codigo del Cliente";
else {
Connection con = conexionSQL.CONN();
if (con == null){
result = "No Hay Datos para Mostrar";
} else {
String query = "Select * from clientes where idcliente =" + idCliente;
PreparedStatement preparedStatement = con.prepareStatement(query);
result = "Busqueda de Datos Correcta";
isSuccess = true;
} catch (Exception ex){
isSuccess = false;
result = "Verifique los Datos";
return result;


Well as observed that that's my code and attempted but has two factors which are commented code the first is:

selectClientes.execute(""); // Can not resolve method 'execute (java.lang.String)

and the second in the Override

@Override //Method does not override method from its superclass

that's my niggle I do not understand how I can do to make me query consisting of editext = that will be the name or names that seeketh, and the button to execute the action of select * from, you understand me

and I would like to step I make when entering the layout from the menu to load and show me the data, without pressing anything

such as doInBackground method that's what I want to do but I guess it's in the onCreate and you will understand me if you need more details, please say, what I want is to solve that little problem

Thanks to All!!

Answer Source

Of course app can't resolve method execute, because ArrayList doesn't have it.

SelectClientes extends ArrayList

SelectClientes should extend AsyncTask.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download